제출 #800194

#제출 시각아이디문제언어결과실행 시간메모리
800194AntekbSalesman (IOI09_salesman)C++17
100 / 100
469 ms30212 KiB
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") //#pragma GCC optimize("trapv") #define st first #define nd second #define pb push_back #define eb emplace_back #define pp(x) pop_back(x) #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define rev(x) reverse(all(x)) #define sor(x) sort(all(x)) #define sz(x) (int)(x).size() #define rsz(x) resize(x) using namespace std; ///~~~~~~~~~~~~~~~~~~~~~~~~~~ template <typename H, typename T> ostream& operator<<(ostream& os, pair<H, T> m){ return os <<"("<< m.st<<", "<<m.nd<<")"; } template <typename H> ostream& operator<<(ostream& os, vector<H> V){ os<<"{"; for(int i=0; i<V.size(); i++){ if(i)os<<", "; os<<V[i]; } os<<"}"; return os; } void debug(){cerr<<"\n";} template <typename H, typename... T> void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);} #define deb(x...) cerr<<#x<<" = ";debug(x); //#define deb(x...) ; ///~~~~~~~~~~~~~~~~~~~~~~~~~ typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<pii > vii; typedef vector<ll> vl; typedef vector<pll> vll; typedef string str; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int K=19, N=1<<K, INF=1e9+5, mod2=1e9+7, mod=998244353; struct modint{ int n=0; modint(){} modint(ll x){ n=x%mod; if(n<0)n+=mod; } operator int(){ return n; } modint operator+(modint a){a.n = n+a.n; if(a.n>=mod)a.n-=mod;return a;} modint operator+=(modint a){return (*this)=(*this)+a;} modint operator-(modint a){a.n = n-a.n; if(a.n<0)a.n+=mod;return a;} modint operator-=(modint a){return (*this)=(*this)-a;} modint operator*(modint a){a.n = (n*1ll*a.n)%mod; return a;} modint operator*=(modint a){return (*this)=(*this)*a;} modint operator^(const ll &m)const{ modint a(1); if(m==0)return a; if(m==1)return (*this); a=(*this)^(m/2); a*=a; return a*((*this)^(m&1)); } modint odw(){ return (*this)^((ll)mod-2); } modint operator/(modint a){return (*this)*a.odw();} modint operator/=(modint a){return (*this)=(*this)/a;} bool operator==(modint a){return a.n==n;} friend ostream& operator<<(ostream& os, modint m) { return os << m.n; } }; modint fact[N], fact2[N]; typedef vector<modint> vm; void factinit(){ fact[0]=1; for(int i=1; i<N; i++){ fact[i]=(fact[i-1]*modint(i))%mod; } fact2[N-1]=fact[N-1].odw(); for(int i=N-2; i>=0; i--){ fact2[i]=(fact2[i+1]*modint(i+1))%mod; } } modint npok(int _n, int _k){ if(_n<_k)return 0; return fact[_n]*fact2[_k]*fact2[_n-_k]; } int los(int a, int b){ return a+(rng())%(b-a+1); } int dp[N]; int tab[N+N], tab2[N+N];//gora, dol void ust(int p, int c){ for(p+=N; p>0; p>>=1){ tab[p]=max(tab[p], c); } } int get(int l, int r){ int ans=-1e9; for(l+=N, r+=N; l<r; l>>=1, r>>=1){ if(l&1)ans=max(ans, tab[l++]); if(r&1)ans=max(ans, tab[--r]); } return ans; } void ust2(int p, int c){ for(p+=N; p>0; p>>=1){ tab2[p]=max(tab2[p], c); } } int get2(int l, int r){ int ans=-1e9; for(l+=N, r+=N; l<r; l>>=1, r>>=1){ if(l&1)ans=max(ans, tab2[l++]); if(r&1)ans=max(ans, tab2[--r]); } return ans; } int main(){ //factinit(); for(int i=0; i<N+N; i++)tab[i]=tab2[i]=-1e9; int n, u, d, S; cin>>n>>u>>d>>S; vector<pair<int, pii> > V, V2; for(int i=0; i<n; i++){ int t, l, w; cin>>t>>l>>w; V.eb(t, mp(l, w)); } sor(V); ust(S, -S*u); ust2(S, S*d); int pocz=0; for(int i=0; i<n;i++){ V2.pb(V[i]); if(i==n-1 || V[i+1].st!=V[i].st){ vi dol(V2.size()), gora(V2.size()); for(int j=0; j<V2.size(); j++){ dp[pocz+j]=-1e9; gora[j]=get(V2[j].nd.st, N)+V2[j].nd.st*u; dol[j]=get2(0, V2[j].nd.st+1)-V2[j].nd.st*d; } //deb(V2, gora, dol); int opt=-1e9; for(int j=0; j<V2.size(); j++){ if(j==0)opt=max({opt, dol[j], gora[j]}); else opt=max({opt-d*(V2[j].nd.st-V2[j-1].nd.st), dol[j], gora[j]}); opt+=V2[j].nd.nd; dp[pocz+j]=max(dp[pocz+j], opt); } opt=-1e9; for(int j=V2.size()-1;j>=0; j--){ if(j+1==V2.size())opt=max({opt, dol[j], gora[j]}); else opt=max({opt-u*(V2[j+1].nd.st-V2[j].nd.st), dol[j], gora[j]}); opt+=V2[j].nd.nd; dp[pocz+j]=max(dp[pocz+j], opt); } for(int j=0; j<V2.size(); j++){ ust(V2[j].nd.st, dp[j+pocz]-u*V2[j].nd.st); ust2(V2[j].nd.st, dp[j+pocz]+d*V2[j].nd.st); } //deb(dp[pocz]); V2.clear(); pocz=i+1; } } int t=max(get2(0, S+1)-d*S, get(S, N)+u*S); cout<<t; }

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

salesman.cpp: In function 'int main()':
salesman.cpp:168:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  168 |    for(int j=0; j<V2.size(); j++){
      |                 ~^~~~~~~~~~
salesman.cpp:175:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  175 |    for(int j=0; j<V2.size(); j++){
      |                 ~^~~~~~~~~~
salesman.cpp:183:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  183 |     if(j+1==V2.size())opt=max({opt, dol[j], gora[j]});
      |        ~~~^~~~~~~~~~~
salesman.cpp:188:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  188 |    for(int j=0; j<V2.size(); j++){
      |                 ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...