제출 #1106889

#제출 시각아이디문제언어결과실행 시간메모리
1106889InvMOD수열 (APIO14_sequence)C++14
22 / 100
823 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define gcd __gcd #define sz(v) (int) v.size() #define pb push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define dbg(x) "[" #x " = " << (x) << "]" ///#define int long long using ll = long long; using ld = long double; using ull = unsigned long long; template<typename T> bool ckmx(T& a, const T& b){if(a <= b) return a = b, true; return false;} template<typename T> bool ckmn(T& a, const T& b){if(a >= b) return a = b, true; return false;} const int N = 1e5+5; const int K = 205; const ll INF = 1e18; ll n, k, a[N], pref[N], dp[K][N], trace[K][N]; namespace Brute{ const int N = 1e3+5; ll dp[K][N], trace[K][N]; void process() { for(int i = 1; i <= n; i++){ dp[0][i] = 0; for(int j = 1; j <= k; j++){ for(int x = j+1; x <= i; x++){ if(ckmx(dp[j][i], dp[j-1][x-1] + (pref[i] - pref[x-1]) * pref[x-1])){ trace[j][i] = x; } } } } cout << dp[k][n] <<"\n"; vector<int> path; for(int cur_k = k, cur_pos = n; cur_k; cur_pos = trace[cur_k][cur_pos]-1, --cur_k){ path.push_back(trace[cur_k][cur_pos]-1); } reverse(all(path)); for(int i = 0; i < sz(path); i++) cout << path[i] <<" "; cout <<"\n"; return; } } struct Line{ ld a,b; int id; Line(ld a = 0, ld b = 0, int id = 0): a(a), b(b), id(id) {} ld intersect(Line& x){return (x.b - b)/(a - x.a);} bool operator < (const Line& x) const{return a < x.a;} }; struct CHT{ deque<pair<Line,ld>> dq; void ins(Line x){ while(!dq.empty()){ if(dq.back().first.a != x.a){ if(dq.back().second >= dq.back().first.intersect(x)) dq.pop_back(); else{ break; } } else{ if(dq.back().first.b <= x.b) dq.pop_back(); else{ return; } } } if(dq.empty()){ dq.push_back(make_pair(x, -INF)); } else dq.push_back(make_pair(x, dq.back().first.intersect(x))); return; } Line get(ll x){ while(dq.size() > 1 && dq[1].second <= x) dq.pop_front(); dq.front().second = -INF; return dq.front().first; } }; void solve() { cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; pref[i] = a[i] + pref[i-1]; } for(int i = 1; i <= k; i++){ CHT hull; for(int j = 1; j <= n; j++){ hull.ins(Line(pref[j-1], dp[i-1][j-1] - pref[j-1] * pref[j-1], j)); } for(int j = 1; j <= n; j++){ Line x = hull.get(pref[j]); ll aL = x.a, bL = x.b; dp[i][j] = aL * pref[j] + bL; trace[i][j] = x.id; } } cout << dp[k][n] <<"\n"; vector<int> path; for(int cur_k = k, cur_pos = n; cur_k; cur_pos = trace[cur_k][cur_pos]-1, cur_k--){ path.push_back(trace[cur_k][cur_pos]-1); } reverse(all(path)); for(int i = 0; i < sz(path); i++) cout << path[i] <<" "; cout <<"\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int t = 1; //cin >> t; while(t--) solve(); return 0; }

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

sequence.cpp: In function 'void Brute::process()':
sequence.cpp:57:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   57 |         for(int i = 0; i < sz(path); i++) cout << path[i] <<" "; cout <<"\n";
      |         ^~~
sequence.cpp:57:66: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   57 |         for(int i = 0; i < sz(path); i++) cout << path[i] <<" "; cout <<"\n";
      |                                                                  ^~~~
sequence.cpp: In function 'void solve()':
sequence.cpp:134:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  134 |     for(int i = 0; i < sz(path); i++) cout << path[i] <<" "; cout <<"\n";
      |     ^~~
sequence.cpp:134:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  134 |     for(int i = 0; i < sz(path); i++) cout << path[i] <<" "; cout <<"\n";
      |                                                              ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:145:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:146:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  146 |         freopen(name".OUT","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...