Submission #930468

#TimeUsernameProblemLanguageResultExecution timeMemory
930468guagua0407Aliens (IOI16_aliens)C++17
12 / 100
232 ms2648 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #include "aliens.h" using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0}; void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } bool eat(pair<int,int> a,pair<int,int> b){ return min(b.f,b.s)<=min(a.f,a.s) and max(b.f,b.s)>=max(a.f,a.s); } const int mxn=505; const ll inf=1e18; vector<vector<ll>> dp(mxn,vector<ll>(mxn,inf)); vector<int> x,y; ll cost(int l,int r){ ll a=(max(x[r],y[r])-min(x[l],y[l])+1); ll b=(l==1?0:max(0,max(x[l-1],y[l-1])-min(x[l],y[l])+1)); return a*a-b*b; } ll solve(int n,int m,int k){ ll ans=inf; dp[0][0]=0; for(int t=1;t<=k;t++){ for(int i=1;i<=n;i++){ for(int j=0;j<i;j++){ dp[i][t]=min(dp[i][t],dp[j][t-1]+cost(j+1,i)); } } ans=min(ans,dp[n][t]); } return ans; } ll take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c){ vector<pair<int,int>> vec(n); for(int i=0;i<n;i++){ vec[i]={r[i],c[i]}; } sort(all(vec)); vector<pair<int,int>> st; for(int i=0;i<n;i++){ while(!st.empty() and eat(st.back(),vec[i])){ st.pop_back(); } if(st.empty() or !eat(vec[i],st.back())){ st.push_back(vec[i]); } } x.push_back(-1); y.push_back(-1); for(auto v:st){ x.push_back(v.f); y.push_back(v.s); } return solve(st.size(),m,k); } //maybe its multiset not set //yeeorz //laborz

Compilation message (stderr)

aliens.cpp: In function 'void setIO(std::string)':
aliens.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aliens.cpp:17:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen((s + ".out").c_str(), "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...