# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
674337 | 2022-12-23T17:46:12 Z | QwertyPi | Hidden Sequence (info1cup18_hidden) | C++14 | 400 ms | 376 KB |
#include <bits/stdc++.h> #define fi first #define se second #define pii pair<int, int> #ifndef TEST #include "grader.h" #endif using namespace std; vector<int> a; #ifdef TEST bool isSubsequence(vector<int> S){ cout << "QRY "; for(auto i : S) cout << i << ' '; int l = 0, r = 0; while(l < a.size() && r < S.size()){ if(a[l] != S[r]) l++; else l++, r++; } cout << (r == S.size() ? "YES" : "NO") << endl; return r == S.size(); } #else bool isSubsequence(vector<int> S); #endif bool flipped = false; bool iss(vector<int> S){ if(flipped) for(auto& i : S) i = 1 - i; return isSubsequence(S); } int dp[201][201]; vector<int> findSequence(int N){ int c0 = 0, c1 = 0; for(int i = 1; i <= N / 2 + 1; i++){ vector<int> a; for(int j = 0; j < i; j++) a.push_back(0); if(!isSubsequence(a)){ c0 = i - 1, c1 = N - (i - 1); break; } } for(int i = 1; i <= N / 2 + 1; i++){ vector<int> a; for(int j = 0; j < i; j++) a.push_back(1); if(!isSubsequence(a)){ c0 = N - (i - 1), c1 = i - 1; break; } } if(c0 >= c1) flipped = true, swap(c0, c1); for(int l = 0; l <= c0; l++){ for(int r = 0; r <= c0; r++){ if(l - 1 < r) dp[l][r] = -1; else if(l - 1 > r) dp[l][r] = -2; else dp[l][r] = 0; } } for(int l = 0; l <= c0; l++){ for(int r = l; r <= c0; r++){ int d = r - l; int quota = (N / 2 + 1) - (c0 - d); int ll = 0, rr = quota; while(ll != rr){ vector<int> qry; for(int j = 0; j < l; j++){ qry.push_back(0); } for(int j = 1; j <= (ll + rr + 1) / 2; j++){ qry.push_back(1); } for(int j = r; j < c0; j++){ qry.push_back(0); } if(iss(qry)){ ll = (ll + rr + 1) / 2; }else{ rr = (ll + rr + 1) / 2 - 1; } } dp[l][r] = (ll == quota ? -1 : ll); } } dp[0][c0] = c1; for(int tr = 0; tr < c0 / 2; tr++){ for(int d = c0 - 1; d >= 0; d--){ for(int i = 0; i < c0 - d; i++){ for(int j = i + d; j <= i + d; j++){ if(dp[i][i] != -1 && dp[i][j + 1] != -1) dp[i + 1][j + 1] = dp[i][j + 1] - dp[i][i]; if(dp[j + 1][j + 1] != -1 && dp[i][j + 1] != -1) dp[i][j] = dp[i][j + 1] - dp[j + 1][j + 1]; if(dp[i][j] == -1 && dp[i + 1][j] != -1 && dp[i][j + 1] != -1 && dp[i + 1][j + 1] != -1) dp[i][j] = dp[i + 1][j] + dp[i][j + 1] - dp[i + 1][j + 1]; if(dp[i][j] != -1 && dp[i + 1][j] == -1 && dp[i][j + 1] != -1 && dp[i + 1][j + 1] != -1) dp[i + 1][j] = dp[i][j] - dp[i][j + 1] + dp[i + 1][j + 1]; if(dp[i][j] != -1 && dp[i + 1][j] != -1 && dp[i][j + 1] == -1 && dp[i + 1][j + 1] != -1) dp[i][j + 1] = dp[i][j] - dp[i + 1][j] + dp[i + 1][j + 1]; if(dp[i][j] != -1 && dp[i + 1][j] != -1 && dp[i][j + 1] != -1 && dp[i + 1][j + 1] == -1) dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j]; } } } } vector<int> ans; int tot = 0, s = 0; for(int i = 0; i <= c0; i++){ tot += dp[i][i] < 0 ? 0 : dp[i][i]; s += dp[i][i] < 0; } for(int i = 0; i <= c0; i++){ if(dp[i][i] == -1){ dp[i][i] = (c1 - tot) / s; } } for(int i = 0; i <= c0; i++){ for(int j = 0; j < dp[i][i]; j++) ans.push_back(1); if(i != c0) ans.push_back(0); } if(flipped){ for(auto& i : ans) i = 1 - i; } return ans; } #ifdef TEST int main(){ int n; cin >> n; vector<int> a; for(int i = 0; i < n; i++){ int v; cin >> v; a.push_back(v); } ::a = a; vector<int> ans = findSequence(n); for(auto i : ans) cout << i << ' '; cout << endl; } #endif
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 208 KB | Output is correct: Maximum length of a query = 5 |
2 | Correct | 1 ms | 208 KB | Output is correct: Maximum length of a query = 6 |
3 | Correct | 1 ms | 208 KB | Output is correct: Maximum length of a query = 5 |
4 | Correct | 1 ms | 208 KB | Output is correct: Maximum length of a query = 5 |
5 | Correct | 1 ms | 208 KB | Output is correct: Maximum length of a query = 4 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 284 ms | 312 KB | Output is correct: Maximum length of a query = 83 |
2 | Correct | 304 ms | 336 KB | Output is correct: Maximum length of a query = 90 |
3 | Correct | 307 ms | 372 KB | Output is correct: Maximum length of a query = 96 |
4 | Correct | 202 ms | 376 KB | Output is correct: Maximum length of a query = 77 |
5 | Correct | 306 ms | 372 KB | Output is correct: Maximum length of a query = 95 |
6 | Correct | 190 ms | 364 KB | Output is correct: Maximum length of a query = 87 |
7 | Correct | 285 ms | 376 KB | Output is correct: Maximum length of a query = 97 |
8 | Correct | 221 ms | 312 KB | Output is correct: Maximum length of a query = 83 |
9 | Correct | 325 ms | 336 KB | Output is correct: Maximum length of a query = 101 |
10 | Execution timed out | 402 ms | 336 KB | Time limit exceeded |
11 | Halted | 0 ms | 0 KB | - |