Submission #532107

#TimeUsernameProblemLanguageResultExecution timeMemory
532107alanlJJOOII 2 (JOI20_ho_t2)C++14
0 / 100
1 ms312 KiB
#include <bits/stdc++.h> #define pb push_back #define F first #define S second #define rep(X, a,b) for(int X=a;X<b;++X) #define ALL(a) (a).begin(), (a).end() #define SZ(a) (int)(a).size() #define NL "\n" using namespace std; typedef pair<long long,long long> pll; typedef pair<int,int> pii; typedef long long ll; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; } template<typename A> ostream& operator<<(ostream &os, const vector<A> &p){ for(const auto &a:p) os << a << " "; os << "\n"; return os; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin>>n>>k; string str; cin>>str; string cc; int st=0, end=n-1;; while(st<n && str[st]!='J') st++; while(end>=0 && str[end]!='I') end--; rep(i,st,end+1) cc+=str[i]; if(end-st<2){ cout<<-1<<NL; return 0; } end++; ll cur=st, cnt=0, ans=0; while(cur<end && cnt<k){ if(str[cur]!='J') ans++; else cnt++; cur++; } if(cnt!=k){ cout<<-1<<NL; return 0; } cnt=0; while(cur<end && cnt<k){ if(str[cur]!='O') ans++; else cnt++; cur++; } if(cnt!=k){ cout<<-1<<NL; return 0; } cnt=0; while(cur<end && cnt<k){ if(str[cur]!='I') ans++; else cnt++; cur++; } if(cnt!=k){ cout<<-1<<NL; return 0; } cout<<ans<<NL; //string target; //rep(i,0,k) target+='J'; //rep(i,0,k) target+='O'; //rep(i,0,k) target+='I'; //vector<vector<ll>> dp(n+1, vector<ll>(n+1,1)); //dp[0][0]=0; //rep(i,1,cc.size()){ //for(int j=1;j<=i;++j){ //if(cc[i]==target[j]) dp[i][j]=dp[i-1][j-1]; //} //} }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...