Submission #4089106
Source Code Expand
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll const mod = 1e9+7; #define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) vector<ll> dp(1<<25,-1); int a[25]; bool b[25]; ll rec(int s,int c) { if (dp[s] > -1) return dp[s]; dp[s] = 0; if (a[c] > -1) { if (a[c]%5 > 0 && a[c]%5 < 4 && ((s>>(a[c]-1))&1) != ((s>>(a[c]+1)&1))) return 0; if (a[c] > 4 && a[c] < 20 && ((s>>(a[c]-5))&1) != ((s>>(a[c]+5))&1)) return 0; return dp[s] = rec(s^(1<<a[c]),c-1); } for (int i = 0;i < 25;++i) if (((s>>i)&1) && !b[i]) { if (i%5 > 0 && i%5 < 4 && ((s>>(i-1))&1) != ((s>>(i+1)&1))) continue; else if (i > 4 && i < 20 && ((s>>(i-5))&1) != ((s>>(i+5))&1)) continue; else { dp[s] += rec(s^(1<<i),c-1); dp[s] %= mod; } } return dp[s]; } int main() { for (int i = 0;i < 25;++i) { a[i] = -1; b[i] = false; } for (int i = 0;i < 25;++i) { int x; cin >> x; if (x) { a[x-1] = i; b[i] = true; } } dp[0] = 1; cout << rec((1<<25)-1,24) << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 25個の整数 |
User | koikotya |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1502 Byte |
Status | MLE |
Exec Time | 116 ms |
Memory | 262400 KB |
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 30 | 0 / 70 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Subtask1 | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, test-1-01.txt, test-1-02.txt, test-1-03.txt, test-1-04.txt, test-1-05.txt, test-1-06.txt, test-1-07.txt, test-1-08.txt, test-1-09.txt, test-1-10.txt, test-1-11.txt, test-1-12.txt, test-1-13.txt, test-1-14.txt, test-1-15.txt |
Subtask2 | sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, test-1-01.txt, test-1-02.txt, test-1-03.txt, test-1-04.txt, test-1-05.txt, test-1-06.txt, test-1-07.txt, test-1-08.txt, test-1-09.txt, test-1-10.txt, test-1-11.txt, test-1-12.txt, test-1-13.txt, test-1-14.txt, test-1-15.txt, test-2-01.txt, test-2-02.txt, test-2-03.txt, test-2-04.txt, test-2-05.txt, test-2-06.txt, test-2-07.txt, test-2-08.txt, test-2-09.txt, test-2-10.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample-01.txt | MLE | 116 ms | 262400 KB |
sample-02.txt | MLE | 67 ms | 262400 KB |
sample-03.txt | MLE | 67 ms | 262400 KB |
sample-04.txt | MLE | 67 ms | 262400 KB |
test-1-01.txt | MLE | 67 ms | 262400 KB |
test-1-02.txt | MLE | 67 ms | 262400 KB |
test-1-03.txt | MLE | 67 ms | 262400 KB |
test-1-04.txt | MLE | 67 ms | 262400 KB |
test-1-05.txt | MLE | 67 ms | 262400 KB |
test-1-06.txt | MLE | 67 ms | 262400 KB |
test-1-07.txt | MLE | 67 ms | 262400 KB |
test-1-08.txt | MLE | 67 ms | 262400 KB |
test-1-09.txt | MLE | 67 ms | 262400 KB |
test-1-10.txt | MLE | 67 ms | 262400 KB |
test-1-11.txt | MLE | 67 ms | 262400 KB |
test-1-12.txt | MLE | 67 ms | 262400 KB |
test-1-13.txt | MLE | 67 ms | 262400 KB |
test-1-14.txt | MLE | 67 ms | 262400 KB |
test-1-15.txt | MLE | 67 ms | 262400 KB |
test-2-01.txt | MLE | 68 ms | 262400 KB |
test-2-02.txt | MLE | 67 ms | 262400 KB |
test-2-03.txt | MLE | 67 ms | 262400 KB |
test-2-04.txt | MLE | 69 ms | 262400 KB |
test-2-05.txt | MLE | 68 ms | 262400 KB |
test-2-06.txt | MLE | 103 ms | 262400 KB |
test-2-07.txt | MLE | 92 ms | 262400 KB |
test-2-08.txt | MLE | 94 ms | 262400 KB |
test-2-09.txt | MLE | 110 ms | 262400 KB |
test-2-10.txt | MLE | 90 ms | 262400 KB |