(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.

Submission #386248

#TimeUsernameProblemLanguageResultExecution timeMemory
386248patrikpavic2Longest beautiful sequence (IZhO17_subsequence)C++17
100 / 100
5069 ms93528 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]; 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 j = 0;j < BS;j++){ int ds = __builtin_popcount(i & j); if(k - ds >= 0 && k - ds <= 10 && naj[(j << 10) + (x & (BS - 1))][k - ds] > ret){ ret = naj[(j << 10) + (x & (BS - 1))][k - ds]; GDJE = naj2[(j << 10) + (x & (BS - 1))][k - ds]; } } return ret; } int main(){ 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; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
subsequence.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
subsequence.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |   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...