제출 #1144069

#제출 시각아이디문제언어결과실행 시간메모리
1144069agrim_09Solar Storm (NOI20_solarstorm)C++20
100 / 100
260 ms171760 KiB
// THIS IS NOT MY CODE (SOURCE : OFFICIAL SOLN OF NOI 2020) // I AM USING THIS TO CHECK MY IMPLEMENTATION ERROR // #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 = 1e6+5; 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 A[N], prefix[N]; int V[N]; int nxt[N], before[N], parent[N]; vector<int> adj[N]; int n, s, ans_start; int ans = 0; vector<int> LOL; void dfs(int u) { LOL.push_back(u); if(u != n) { int l = before[u]; int r = nxt[LOL[max(0LL, (int)LOL.size() - s)]] - 1; int candidate = prefix[r] - (l == -1 ? 0 : prefix[l]); //cout<<"DBG --> "<<u<<" : "<<l<<" "<<r<<" : "<<candidate<<endl; if(candidate > ans) { ans = candidate; ans_start = u; } } for(auto v : adj[u]) { dfs(v); } LOL.pop_back(); } signed main(){ fastio; //judge(); int diff; int k; cin>>n>>s>>k; A[0] = 0; for(int i = 1; i < n; i++) { cin>>diff; A[i] = A[i - 1] + diff; } for(int i = 0; i < n; i++) { cin>>V[i]; prefix[i] = (i == 0 ? 0 : prefix[i - 1]) + V[i]; } prefix[n] = prefix[n - 1]; A[n] = A[n - 1] + 2*k; int current_ptr = 0; nxt[n] = n; for(int i = 0; i < n; i++) { for(int j = current_ptr; j <= n; j++) { if(A[j] - A[i] > k) { current_ptr = j; nxt[i] = j; break; } } } current_ptr = n; for(int i = n; i >= 0; i--) { for(int j = current_ptr; j >= -1; j--) { if(j == -1 or A[i] - A[j] > k) { current_ptr = j; before[i] = j; break; } } } // for(int i = 0; i < n; i++) cout<<i<<" Before: "<<before[i]<<", Next: "<<nxt[i]<<endl; for(int i = 0; i < n; i++) { int jump_to = nxt[i]; if(jump_to != n) { jump_to = nxt[jump_to] - 1; } //cout<<i<<" --> "<<jump_to<<endl; adj[jump_to].push_back(i); parent[i] = jump_to; } dfs(n); vector<int> Q; for(int i = 0; i < s; i++) { Q.push_back(ans_start); ans_start = parent[ans_start]; if(ans_start == n) break; } cout<<Q.size()<<endl; for(auto v : Q) cout<<v + 1<<" "; cout<<endl; }

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

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