제출 #1143687

#제출 시각아이디문제언어결과실행 시간메모리
1143687agrim_09Solar Storm (NOI20_solarstorm)C++20
36 / 100
357 ms184468 KiB
// #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define endl '\n'; #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define py cout << "YES" << endl; #define pn cout << "NO" << endl; #define pb push_back #define int long long typedef long double lld; #define double lld typedef long long ll; typedef unsigned long long ull; const ll inf = 1e18; const ll mod = 1e9+7; const int N = 2e5; vector<int>primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; // Check for queue, priorioty_queue, stack, ordered_set solutions // stack => LIFO (whatever goes in last comes out last) // queue => FIFO (whatever goes in first comes out first) // priority_queue => Dynamic queries of minimum/maximum // ordered_set => set in vector form //[order_of_key(k) gives number of elements less than k, while find_by_order(i) gives i^th element] // To comment multiple lines : ctrl + / // To find and replace : ctrl+H void judge(){ srand(time(NULL)); #ifndef ONLINE_JUDGE freopen("1.txt","r",stdin); freopen("2.txt","w",stdout); freopen("Error.txt", "w", stderr); #define debug(x...) cerr << #x <<" = "; _print(x); cerr << endl; #else #define debug(x...) #endif } void usaco(string s) { freopen((s + ".in").c_str(),"r",stdin); freopen((s + ".out").c_str(),"w",stdout); } int n,d,k; vector<int>a,vals; vector<int>adj,extra, prefix,dp; int curr_sum = 0; int summation(int l, int r){ if(l>r){ return 0; } if(l==0){ return prefix[r]; } return prefix[r] - prefix[l-1]; } void build_adj(){ prefix.resize(n); prefix[0] = vals[0]; for(int i = 1;i<n;i++) prefix[i] = prefix[i-1] + vals[i]; adj.resize(n+1), extra.resize(n); vector<int>pref(n); pref[0] = 0; for(int i = 1;i<n;i++) pref[i] = pref[i-1] + a[i-1]; for(int i = 1;i<n;i++){ auto it = upper_bound(pref.begin(),pref.end(),pref[i-1]+k); adj[i-1] = it - pref.begin(); } extra[0] = 0; for(int i = 1;i<n;i++){ auto it = lower_bound(pref.begin(),pref.end(),pref[i]-k); int idx = it - pref.begin(); extra[i] = summation(idx,i-1); } adj[n-1] = n, adj[n] = n; } vector<int>v; void dfs(int node, int par, vector<vector<int>>&list){ if(node!=n ){ int x = v.size(); int p = x - d; p = max(p,0LL); dp[node] = v[p]; } v.pb(node); for(auto child : list[node]){ if(child==par){ continue; } dfs(child,node,list); } v.pop_back(); } void final_answer(){ vector<vector<int>>list(n+1); for(int i = 0;i<n;i++){ list[i].pb(adj[i]); list[adj[i]].pb(i); } dfs(n,n,list); int best = 0, maxi = summation(0,dp[0]-1) + extra[0]; for(int i = 1;i<n;i++){ int curr = summation(i,dp[i]-1) + extra[i]; if(curr>maxi){ maxi = curr, best = i; } } vector<int>answer; while(d--){ if(best==n){ break; } answer.pb(best); best = adj[best]; } cout << answer.size() << endl; for(auto x : answer){ cout << x + 1 << ' '; } } signed main(){ fastio; //judge(); cin >> n >> d >> k; a.resize(n-1), vals.resize(n), dp.resize(n); extra.resize(n); for(auto &x : a) cin >> x; for(auto &x : vals) cin >> x; build_adj(); final_answer(); }

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

SolarStorm.cpp: In function 'void judge()':
SolarStorm.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("1.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
SolarStorm.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen("2.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
SolarStorm.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     freopen("Error.txt", "w", stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
SolarStorm.cpp: In function 'void usaco(std::string)':
SolarStorm.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen((s + ".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SolarStorm.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen((s + ".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...