제출 #836096

#제출 시각아이디문제언어결과실행 시간메모리
836096josanneo22Sightseeing in Kyoto (JOI22_kyoto)C++17
100 / 100
19 ms5580 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define mp make_pair #define pb push_back #define pii pair<int,int> #define fi first #define se second #define all(x) x.begin(), x.end() #define ar array /* observation: with a shit ton of inequalities: we only go up in the middle if (Ab-Ac)/(b-c)<(Bx-By)/(x-y)<(Aa-Ab)/(a-b) */ //ca compares a's const int N=1e6+6000; int A[N],B[N],aa[N],bb[N]; bool ca(int x,int y,int z) { return (A[x]-A[y])*(x-z)<(A[x]-A[z])*(x-y); } bool cb(int x,int y,int z) { return (B[x]-B[y])*(x-z)<(B[x]-B[z])*(x-y); } bool cab(int x,int y,int z,int w) { return (A[x]-A[y])*(w-z)<(B[z]-B[w])*(y-x); } void solve(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++) cin>>A[i]; for(int i=1;i<=m;i++) cin>>B[i]; int ta=0,tb=0; aa[++ta]=1; bb[++tb]=1; for(int i=2;i<=n;i++){ while(ta>1 && ca(i,aa[ta],aa[ta-1])) ta--; aa[++ta]=i; } for(int i=2;i<=m;i++){ while(tb>1 && cb(i,bb[tb],bb[tb-1])) tb--; bb[++tb]=i; } int x=1,y=1,ans=0; while(x<ta || y<tb){ //if already taken all a's force take y if(x==ta || (y<tb && cab(aa[x],aa[x+1],bb[y],bb[y+1]))){ int cost=(bb[y+1]-bb[y])*A[aa[x]]; y++; ans+=cost; } else{ int cost=(aa[x+1]-aa[x])*B[bb[y]]; x++; ans+=cost; } } cout<<ans<<'\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); clock_t tStart = clock(); int local=0,multi=0,debug=1,tt=1; if(local){ freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); } if(multi) cin>>tt; for(int i=1;i<=tt;i++){ if(debug && multi && local) cout<<"样例 "<<i<<'\n'; solve(); } fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC); }

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

kyoto.cpp: In function 'int main()':
kyoto.cpp:63:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |      freopen("input.txt","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
kyoto.cpp:64:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |      freopen("output.txt","w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...