Submission #250054

#TimeUsernameProblemLanguageResultExecution timeMemory
250054uacoder123Miners (IOI07_miners)C++14
84 / 100
1596 ms187512 KiB
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define FOR(i,a,b) for (auto i = (a); i <= (b); ++i) #define NFOR(i,a,b) for(auto i = (a); i >= (b); --i) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define mp(i,a) make_pair(i,a) #define pb(a) push_back(a) #define bit(x,b) (x&(1LL<<b)) typedef long long int lli; typedef pair <lli,lli> ii; typedef pair <lli,ii> iii; typedef vector <lli> vi; string s; int c=0; map<pair<int,pair<string,string>>,int> m; string s1,s2; int cal(int n) { c++; if(n==s.size()) return(0); if(m.find(mp(n,mp(s1,s2)))!=m.end()) return(m[mp(n,mp(s1,s2))]); string s3=s1,s4=s2; set<char> se; se.insert(s[n]); for(int i=int(s1.size())-1;i>=0;--i) se.insert(s1[i]); if(s1.size()<2) s1+=s[n]; else { s1[0]=s1[1]; s1[1]=s[n]; } int ans=int(se.size())+cal(n+1); s2=s4; se.clear(); se.insert(s[n]); for(int i=int(s2.size())-1;i>=0;--i) se.insert(s2[i]); if(s2.size()<2) s2+=s[n]; else { s2[0]=s2[1]; s2[1]=s[n]; } s1=s3; ans=max(ans,int(se.size()+cal(n+1))); m[mp(n,mp(s3,s4))]=ans; return(ans); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lli test=1; for(;test>0;--test) { int n; cin>>n; s1="",s2=""; cin>>s; cout<<cal(0)<<endl; } return(0); }

Compilation message (stderr)

miners.cpp: In function 'int cal(int)':
miners.cpp:24:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(n==s.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...
#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...