Submission #309861

#TimeUsernameProblemLanguageResultExecution timeMemory
309861KriptonWatching (JOI13_watching)C++14
100 / 100
392 ms27064 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int n,p,q; vector <int> vec[2001]; int v[2001]; int dp[2001][2001];// dp[i][j]=nr minim de garduri MARI ca sa acopere primele i puncte, folosind si j garduri MICI int where_to(int start,int mar) { int r=start,pas=1<<10; while(pas) { if(r+pas<=n&&v[r+pas]-v[start]+1<=mar) r+=pas; pas/=2; } return r; } bool verif(int w) { int i,j; for(i=1; i<=n; i++) vec[i].clear(); for(i=1; i<=n; i++) for(j=0; j<=n; j++) dp[i][j]=INT_MAX; int x=where_to(1,w),y=where_to(1,2*w); vec[x].push_back(1); dp[x][1]=0; vec[y].push_back(0); dp[y][0]=1; for(i=1; i<n; i++) { x=where_to(i+1,w); y=where_to(i+1,2*w); for(j=0; j<vec[i].size(); j++) { if(x!=i&&vec[i][j]+1<=p&&dp[i][vec[i][j]]<dp[x][vec[i][j]+1]) { if(dp[x][vec[i][j]+1]==INT_MAX) vec[x].push_back(vec[i][j]+1); dp[x][vec[i][j]+1]=dp[i][vec[i][j]]; } if(y!=i&&dp[i][vec[i][j]]+1<dp[y][vec[i][j]]) { if(dp[y][vec[i][j]]==INT_MAX) vec[y].push_back(vec[i][j]); dp[y][vec[i][j]]=dp[i][vec[i][j]]+1; } } } for(i=0;i<vec[n].size();i++) if(dp[n][vec[n][i]]<=q) break; if(i==vec[n].size()) return 0; return 1; } int cautbin() { int r=0,pas=1<<30; while(pas) { if(!verif(r+pas)) r+=pas; pas/=2; } return r+1; } int main() { #ifdef HOME freopen("test.in","r",stdin); freopen("test.out","w",stdout); #endif // HOME ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>p>>q; if(p+q>=n) { cout<<1; return 0; } for(int i=1; i<=n; i++) cin>>v[i]; sort(v+1,v+n+1); cout<<cautbin(); return 0; }

Compilation message (stderr)

watching.cpp: In function 'bool verif(int)':
watching.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(j=0; j<vec[i].size(); j++)
      |                  ~^~~~~~~~~~~~~~
watching.cpp:52:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(i=0;i<vec[n].size();i++)
      |             ~^~~~~~~~~~~~~~
watching.cpp:55:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     if(i==vec[n].size())
      |        ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...