Submission #784440

#TimeUsernameProblemLanguageResultExecution timeMemory
784440LyricallyHoliday (IOI14_holiday)C++17
100 / 100
174 ms4152 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int,int> #define pb push_back #define rep(i,n) for(int i=0;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) int read(){int x;scanf("%d",&x);return x;} void print(int x){printf("%d\n",x);} void file(string s) { freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } const int mod=998244353; long long a[100005]; long long n,s,d; long long calc(int x) { long long tot=0; int r=d-2*(s-x); priority_queue<long long,vector<long long>,greater<long long>> pq; for(int i=x;i<s;i++) { tot+=a[i]; pq.push(a[i]); } long long res=0; for(int i=s;i<=n;i++) { if(r<=0){return res;} //d-(i-x) while(pq.size()>r){tot-=pq.top(),pq.pop();} if(pq.size()<r||a[i]>pq.top()) { if(pq.size()==r) { tot-=pq.top();pq.pop(); } pq.push(a[i]);tot+=a[i]; } r--; res=max(res,tot); } return res; } long long findMaxAttraction(int N,int S,int D,int attr[]) { n=N,s=S+1,d=D; rep(i,n){a[i+1]=attr[i];} //往左去到的最远地方 long long res=0; for(int i=1;i<=min(s,20ll);i++) { long long x=calc(i); res=max(res,x); } for(int i=max(s-20,1ll);i<=s;i++) { long long x=calc(i); res=max(res,x); } reverse(a+1,a+n+1); if(s!=1) { s=n-s+1; for(int i=1;i<=min(s,20ll);i++) { long long x=calc(i); res=max(res,x); } for(int i=max(s-20,1ll);i<=s;i++) { long long x=calc(i); res=max(res,x); } } return res; }

Compilation message (stderr)

holiday.cpp: In function 'long long int calc(int)':
holiday.cpp:32:18: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |   while(pq.size()>r){tot-=pq.top(),pq.pop();}
      |         ~~~~~~~~~^~
holiday.cpp:33:15: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |   if(pq.size()<r||a[i]>pq.top())
      |      ~~~~~~~~~^~
holiday.cpp:35:16: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |    if(pq.size()==r)
      |       ~~~~~~~~~^~~
holiday.cpp: In function 'int read()':
holiday.cpp:7:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | int read(){int x;scanf("%d",&x);return x;}
      |                  ~~~~~^~~~~~~~~
holiday.cpp: In function 'void file(std::string)':
holiday.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  freopen((s+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
holiday.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  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...