Submission #1089883

#TimeUsernameProblemLanguageResultExecution timeMemory
1089883KALARRYTricks of the Trade (CEOI23_trade)C++14
15 / 100
1444 ms2097152 KiB
//chockolateman #include<bits/stdc++.h> using namespace std; long long N,K,a[250005],b[250005],dp[250005][205]; vector<pair<int,int>> adj[250005][205]; bool visited[250005][205]; bool used[250005]; void dfs(int startv,int startj) { queue<pair<int,int>> q; q.push({startv,startj}); while(!q.empty()) { int v = q.front().first; int j = q.front().second; q.pop(); if(visited[v][j]) return; visited[v][j] = true; if(j==0) return; for(auto e : adj[v][j]) { int u = e.first; int newj = e.second; if(newj==(j-1)) used[v] = true; q.push({u,newj}); } } } int main() { scanf("%lld%lld",&N,&K); for(long long i = 1 ; i <= N ; i++) scanf("%lld",&a[i]); for(long long i = 1 ; i <= N ; i++) scanf("%lld",&b[i]); for(long long j = 1 ; j <= K ; j++) { dp[0][j%2] = -1e15; for(long long i = 1 ; i <= N ; i++) { dp[i][j%2] = max(dp[i-1][j%2] - a[i],dp[i-1][(j-1)%2] + b[i] - a[i]); if(dp[i][j%2]==dp[i-1][j%2] - a[i]) adj[i][j].push_back({i-1,j}); if(dp[i][j%2] == dp[i-1][(j-1)%2] + b[i] - a[i]) adj[i][j].push_back({i-1,j-1}); } } long long ans = -1e15; for(long long i = 1 ; i <= N ; i++) ans = max(ans,dp[i][K%2]); for(long long i = 1 ; i <= N ; i++) if(dp[i][K%2]==ans) dfs(i,K); printf("%lld\n",ans); for(int i = 1 ; i <= N ; i++) printf("%d",used[i]); return 0; }

Compilation message (stderr)

trade.cpp: In function 'int main()':
trade.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%lld%lld",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
trade.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
trade.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%lld",&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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...