Submission #115682

#TimeUsernameProblemLanguageResultExecution timeMemory
115682suzyBali Sculptures (APIO15_sculpture)C++17
100 / 100
94 ms19072 KiB
#include <stdio.h> #include <string.h> #include <vector> #include <algorithm> using namespace std; typedef long long lli; lli a[2001], p[2001]; int n, L, R; vector<int> con[2001], tmp[2001]; int d1[101][101], d2[2001]; int f1(int c, int k) { if(k>n) return L<=c && c<=R; if(d1[c][k]>=0) return d1[c][k]; for(int i=0;i<con[k].size();i++) { int v=con[k][i]; if(f1(c+1,v+1)) return d1[c][k]=1; } return d1[c][k]=0; } int f2(int k) { if(k>n) return 0; if(d2[k]>=0) return d2[k]; int ret=(1<<30); for(int i=0;i<con[k].size();i++) { int v=con[k][i]; ret=min(ret,f2(v+1)+1); } return d2[k]=ret; } void make(int b) { for(int i=1;i<=n;i++) { tmp[i]=con[i]; con[i].clear(); for(int j=0;j<tmp[i].size();j++) { if((p[tmp[i][j]]-p[i-1])&(1LL<<b)) continue; con[i].push_back(tmp[i][j]); } } } lli solve1() { lli ret=0; for(int b=41;b>=0;b--) { memset(d1,-1,sizeof(d1)); make(b); if(f1(0,1)==0) { for(int i=1;i<=n;i++) con[i]=tmp[i]; ret|=(1LL<<b); } } return ret; } lli solve2() { lli ret=0; for(int b=41;b>=0;b--) { memset(d2,-1,sizeof(d2)); make(b); if(f2(1)>R) { for(int i=1;i<=n;i++) con[i]=tmp[i]; ret|=(1LL<<b); } } return ret; } int main() { scanf("%d %d %d",&n,&L,&R); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); p[i]=p[i-1]+a[i]; } for(int i=1;i<=n;i++) { for(int j=i;j<=n;j++) con[i].push_back(j); } lli res; if(L>1) res=solve1(); else res=solve2(); printf("%lld\n",res); return 0; }

Compilation message (stderr)

sculpture.cpp: In function 'int f1(int, int)':
sculpture.cpp:18:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<con[k].size();i++) {
              ~^~~~~~~~~~~~~~
sculpture.cpp: In function 'int f2(int)':
sculpture.cpp:29:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<con[k].size();i++) {
              ~^~~~~~~~~~~~~~
sculpture.cpp: In function 'void make(int)':
sculpture.cpp:40:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<tmp[i].size();j++) {
               ~^~~~~~~~~~~~~~
sculpture.cpp: In function 'int main()':
sculpture.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&L,&R);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[i]);
   ~~~~~^~~~~~~~~~~~~~
#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...