Submission #530174

#TimeUsernameProblemLanguageResultExecution timeMemory
530174LawlietTeams (CEOI11_tea)C++17
0 / 100
256 ms104516 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1000010; const int INF = 1000000010; int n; int v[MAXN]; int ord[MAXN]; int maxSize[MAXN]; int dp[MAXN], opt[MAXN]; vector<int> indValues[MAXN]; vector<int> transitions[MAXN]; int main() { scanf("%d",&n); for(int i = 1 ; i <= n ; i++) { scanf("%d",&v[i]); indValues[ v[i] ].push_back( i ); } int cnt = 0; for(int i = n ; i > 0 ; i--) while( !indValues[i].empty() ) ord[++cnt] = indValues[i].back(), indValues[i].pop_back(); for(int i = 1 ; i < v[ ord[1] ] ; i++) dp[i] = -INF; dp[ v[ ord[1] ] ] = 1; opt[ v[ ord[1] ] ] = 1; maxSize[ v[ ord[1] ] ] = v[ ord[1] ]; transitions[ v[ ord[1] ] ].push_back( v[ ord[1] ] ); for(int i = v[ ord[1] ] + 1 ; i <= n ; i++) { dp[i] = dp[i - 1]; opt[i] = opt[i - 1]; maxSize[i] = maxSize[i - 1]; if( (i - 1)%maxSize[i - 1] == 0 && (i - 1)/maxSize[i - 1] == dp[i - 1] ) maxSize[i]++; if( v[ ord[i] ] + i - 1 <= n ) transitions[ v[ ord[i] ] + i - 1 ].push_back( i ); for(int j = 0 ; j < (int)transitions[i].size() ; j++) { int last = transitions[i][j]; int newSize = max( maxSize[last - 1] , i - last + 1 ); if( dp[i] < dp[last - 1] + 1 ) dp[i] = dp[last - 1] + 1, maxSize[i] = newSize, opt[i] = last; else if( dp[i] == dp[last - 1] + 1 && maxSize[i] > newSize ) maxSize[i] = newSize, opt[i] = last; } } printf("%d\n",dp[n]); int last = n; for(int i = 1 ; i <= dp[n] ; i++, last = opt[last] - 1) { printf("%d ",last - opt[last] + 1); for(int j = opt[last] ; j <= last ; j++) printf("%d ",ord[j]); printf("\n"); } }

Compilation message (stderr)

tea.cpp: In function 'int main()':
tea.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
tea.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d",&v[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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...