Submission #250048

#TimeUsernameProblemLanguageResultExecution timeMemory
250048uacoder123Miners (IOI07_miners)C++14
84 / 100
1591 ms185656 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; map<pair<int,pair<string,string>>,int> m; int cal(int n,string s1,string s2) { 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=se.size()+cal(n+1,s1,s2); 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]; } ans=max(ans,int(se.size()+cal(n+1,s3,s2))); 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; string s1="",s2=""; cin>>s; cout<<cal(0,s1,s2)<<endl; } return(0); }

Compilation message (stderr)

miners.cpp: In function 'int cal(int, std::__cxx11::string, std::__cxx11::string)':
miners.cpp:21: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...