제출 #787398

#제출 시각아이디문제언어결과실행 시간메모리
787398LIFAliens (IOI16_aliens)C++14
60 / 100
548 ms274032 KiB
#include "aliens.h" #include<bits/stdc++.h> #include<vector> using namespace std; int rr[300005]; int cc[300005]; int color[305][305]; long long int dp[50005][4005]; bool can[500005]; struct node { long long int r; long long int c; }nod[500005]; int nowr[300005]; int nowc[300005]; node first[300005]; bool cmp(node x,node y) { if(x.r == y.r)return x.c > y.c; else return x.r < y.r; } double getk(int num1,int num2,int tim) { long long int x1 = nod[num1+1].r; long long int x2 = nod[num2+1].r; long long int zz = 0; long long int y1 = dp[num1][tim-1] + (nod[num1+1].r) * (nod[num1+1].r) - max(zz,nod[num1].c - nod[num1+1].r + 1) * max(zz,nod[num1].c - nod[num1+1].r + 1); long long int y2 = dp[num2][tim-1] + (nod[num2+1].r) * (nod[num2+1].r) - max(zz,nod[num2].c - nod[num2+1].r + 1) * max(zz,nod[num2].c - nod[num2+1].r + 1); if(x1 == x2) { return 1.0 * (y1-y2) / 1e-9; } else { return 1.0 * (y1-y2) / (x1-x2); } } int q[300005]; long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { for(int i=0;i<r.size();i++)rr[i+1] = r[i]; for(int i=0;i<c.size();i++)cc[i+1] = c[i]; bool flag2 = true; for(int i=1;i<=n;i++) { if(rr[i] > cc[i])swap(rr[i],cc[i]); if(rr[i] != cc[i])flag2 = false; } for(int i=1;i<=n;i++) { for(int j=1;j<=k;j++)dp[i][j] = 1e18; dp[i][0] = 1e18; } dp[0][0] = 0; for(int i=1;i<=n;i++) { first[i].r = rr[i]; first[i].c = cc[i]; } nod[0].r = -10000; nod[0].c = -10000; for(int i=1;i<=n;i++)can[i] = true; long long int maxnc = -1; sort(first+1,first+n+1,cmp); for(int i=1;i<=n;i++) { if(maxnc > first[i].c)can[i] = false; maxnc = max(maxnc,first[i].c); } int num = 0; for(int i=1;i<=n;i++) { if(can[i] == false)continue; num++; nod[num].c = first[i].c; nod[num].r = first[i].r; } sort(nod+1,nod+num+1,cmp); for(int i=1;i<=num;i++) { dp[i][1] = (nod[i].c + 1) * (nod[i].c + 1); } for(int tim=1;tim<=k;tim++) { int h = 1; int t = 0; for(int i=1;i<=num;i++) { while(h < t && getk(i-1,q[t],tim) <= getk(q[t],q[t-1],tim))t--; q[++t] = i-1; while(h < t && (getk(q[h+1],q[h],tim) <= 2 * (nod[i].c+1)))h++; int j = q[h]; long long int zero = 0; long long int del = nod[j].c - nod[j+1].r + 1; long long int sub = max(zero,del) * max(zero,del); long long int add = (nod[i].c - nod[j+1].r + 1) * (nod[i].c - nod[j+1].r + 1); // cout<<tim<<" "<<i<<" "<<j<<endl; dp[i][tim] = dp[j][tim-1] + add - sub; } } //cout<<getk(1,0,2)<<" "<<getk(0,0,2)<<endl; long long int ans = 1e18; for(int i=1;i<=k;i++)ans = min(ans,dp[num][i]); return ans; }

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

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:41:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i=0;i<r.size();i++)rr[i+1] = r[i];
      |              ~^~~~~~~~~
aliens.cpp:42:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for(int i=0;i<c.size();i++)cc[i+1] = c[i];
      |              ~^~~~~~~~~
aliens.cpp:43:7: warning: variable 'flag2' set but not used [-Wunused-but-set-variable]
   43 |  bool flag2 = true;
      |       ^~~~~
#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...