(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

제출 #36128

#제출 시각아이디문제언어결과실행 시간메모리
36128aomeLongest beautiful sequence (IZhO17_subsequence)C++14
100 / 100
5099 ms48776 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int M = 1024; const int INF = 1e9; int n, a[N], b[N], cnt[M]; int f[N], trace[N]; int g[M][M][11]; int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) scanf("%d", &b[i]); for (int i = 0; i < M; ++i) { for (int j = 0; j < 10; ++j) cnt[i] += i >> j & 1; } int pos = 0; f[0] = -INF; for (int i = 1; i <= n; ++i) { int pre = 0, suf = 0; for (int j = 0; j < 10; ++j) { if (a[i] >> j & 1) pre |= 1 << j; } for (int j = 10; j < 20; ++j) { if (a[i] >> j & 1) suf |= 1 << (j - 10); } f[i] = 1; for (int j = 0; j < M; ++j) { int x = j & pre; if (cnt[x] > b[i] || b[i] - cnt[x] > 10) continue; int y = g[j][suf][b[i] - cnt[x]]; if (f[i] < f[y] + 1) { f[i] = f[y] + 1, trace[i] = y; } } for (int j = 0; j < M; ++j) { int x = suf & j; int &y = g[pre][j][cnt[x]]; if (f[y] < f[i]) y = i; } if (f[pos] < f[i]) pos = i; } vector<int> res; int cur = pos; while (cur) { res.push_back(cur), cur = trace[cur]; } reverse(res.begin(), res.end()); printf("%d\n", res.size()); for (int i = 0; i < res.size(); ++i) printf("%d ", res[i]); }

컴파일 시 표준 에러 (stderr) 메시지

subsequence.cpp: In function 'int main()':
subsequence.cpp:52:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", res.size());
                           ^
subsequence.cpp:53:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < res.size(); ++i) printf("%d ", res[i]);
                    ^
subsequence.cpp:15:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
subsequence.cpp:16:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
                                                 ^
subsequence.cpp:17:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
                                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...