제출 #349438

#제출 시각아이디문제언어결과실행 시간메모리
349438tengiz05Aliens (IOI16_aliens)C++17
0 / 100
11 ms492 KiB
#include "aliens.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> using namespace std; typedef long long ll; #define pii pair<int,int> #define all(x) x.begin(), x.end() #define ff first #define ss second ll n, m, k; ll dp[5005][5005]; bool cmp(pii &x, pii &y){ if(x.ff != y.ff)return x.ff < y.ff; return x.ss < y.ss; } vector<pii> a; ll sq(ll t){ return t*t; } ll cost(int i, int j){ assert(j < a.size()); int r1=a[i].ff, c1=a[i].ss; int r2=a[j].ff, c2=a[j].ss; ll r = min(r1,r2), c = max(c1,c2); ll di = c-r+1; ll total = sq(di); if(i==0 || a[i-1].ss <= c-di)return total; return total - sq(a[i-1].ss - (c-di)); } ll take_photos(int Ni, int Mi, int Ki, vector<int> r, vector<int> c){ n = Ni, m = Mi, k = Ki; vector<pii> v; for(int i=0;i<n;i++){ if(r[i] > c[i])swap(r[i],c[i]); v.push_back({r[i],c[i]}); }sort(all(v), cmp); //clearing some unneeded points vector<pii> pre_taza, finals; for(int i=0;i<n;i++){ while(i+1 < n && v[i+1].ff == v[i].ff)i++; pre_taza.push_back(v[i]); }assert(false); n = pre_taza.size(); int mx = 0; for(int i=0;i<n;i++){ mx = max(mx, pre_taza[i].ss); while(pre_taza[i+1].ss <= mx)i++; finals.push_back(pre_taza[i]); }a.push_back({-1,-1}); for(auto x : finals)a.push_back(x); n = finals.size(); //stopping assert(false); //~ for(auto [x,y] : finals)cout << x << '-' << y << '\n'; k = min(k,n); for(int i=1;i<=n;i++){ for(int j=1;j<=k;j++)dp[i][j] = 1e18; } for(int i=1;i<=n;i++){ dp[i][1] = cost(1,i); } for(int i=1;i<=n;i++){ for(int j=2;j<=k;j++){ for(int l=1;l<=i;l++){ dp[i][j] = min(dp[i][j], dp[l-1][j] + cost(l,i)); } } } return dp[n][k]; } /* 5 7 2 0 3 4 4 4 6 4 5 4 6 2 100 1 1 4 4 1 */

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

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from aliens.cpp:5:
aliens.cpp: In function 'll cost(int, int)':
aliens.cpp:23:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  assert(j < a.size());
      |         ~~^~~~~~~~~~
#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...