제출 #386252

#제출 시각아이디문제언어결과실행 시간메모리
386252patrikpavic2Longest beautiful sequence (IZhO17_subsequence)C++17
0 / 100
286 ms262144 KiB
#include <cstdio> #include <cstdlib> #include <algorithm> #include <vector> #define PB push_back using namespace std; const int N = 1e5 + 500; const int MSK = (1 << 20); const int BS = (1 << 10); int n, A[N], K[N], dp[N], rek[N], krj; int naj[MSK][11], sol, naj2[MSK][11]; vector < int > na[BS][11]; void dodaj(int xx, int y, int gdje){ int i = xx >> 10, x = xx & (BS - 1); for(int j = 0;j < BS;j++){ int ds = __builtin_popcount(j & x); if(y > naj[(i << 10) + j][ds]){ naj[(i << 10) + j][ds] = y; naj2[(i << 10) + j][ds] = gdje; } } } int GDJE; int pitaj(int x, int k){ int ret = 0, i = x >> 10; for(int kk = 0;kk < 11;kk++){ if(k - kk < 0 || k - kk > 10) continue; for(int j : na[i][kk]){ if(naj[(j << 10) + (x & (BS - 1))][k - kk] > ret){ ret = naj[(j << 10) + (x & (BS - 1))][k - kk]; GDJE = naj2[(j << 10) + (x & (BS - 1))][k - kk]; } } } return ret; } int main(){ freopen("subsequence.in", "r", stdin); freopen("subsequence.out", "w", stdout); for(int i = 0;i < BS;i++) for(int j = 0;j < BS;j++) na[i][__builtin_popcount(i & j)].PB(j); scanf("%d", &n); for(int i = 0;i < n;i++) scanf("%d", A + i); for(int i = 0;i < n;i++) scanf("%d", K + i); for(int i = 0;i < n;i++){ dp[i] = pitaj(A[i], K[i]) + 1; if(dp[i] > 1){ rek[i] = GDJE; } if(sol < dp[i]){ sol = dp[i]; krj = i; } dodaj(A[i], dp[i], i); } printf("%d\n", sol); vector < int > fin; for(;;){ fin.PB(krj + 1); if(dp[krj] == 1) break; krj = rek[krj]; } reverse(fin.begin(), fin.end()); for(int x : fin) printf("%d ", x); printf("\n"); return 0; }

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

subsequence.cpp: In function 'int main()':
subsequence.cpp:46:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   46 |  freopen("subsequence.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:47:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   47 |  freopen("subsequence.out", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subsequence.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
subsequence.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
subsequence.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |   scanf("%d", K + 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...