제출 #385637

#제출 시각아이디문제언어결과실행 시간메모리
385637strawberry2005JJOOII 2 (JOI20_ho_t2)C++11
0 / 100
2 ms364 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9+7; #define deb(x) cout<<#x<<": "<<x<<endl int iceil(int a, int b) { return (a + b - 1) / b; } bool isSubSequence(string str1, string str2,int m, int n){ // Base Cases if (m == 0) return true; if (n == 0) return false; // If last characters of two // strings are matching if (str1[m - 1] == str2[n - 1]) return isSubSequence(str1, str2, m - 1, n - 1); // If last characters are // not matching return isSubSequence(str1, str2, m, n - 1); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(20); #ifdef strawberryshaker2005 freopen("input.txt", "r", stdin); #endif int n,k; cin>>n>>k; string s; cin>>s; deque<char> f; for(int i=0;i<s.size();i++) f.push_back(s[i]); int j=count(s.begin(),s.end(),'J'),o=count(s.begin(),s.end(),'O'),eye=count(s.begin(),s.end(),'I'); //deb(j); while(true){ if(f[0]=='O'&&o>k){ o--; f.pop_front(); } else if(f[0]=='I'&&eye>k){ eye--; f.pop_front(); } else break; } while(true){ if(f[f.size()-1]=='O'&&o>k){ o--; f.pop_back(); } else if(f[f.size()-1]=='J'&&j>k){ j--; f.pop_back(); } else break; } s.clear(); for(int i=0;i<f.size();i++){ s.push_back(f[i]); } //deb(s); int m=3*k,compare_size=s.size(); string compare=""; for(int i=0;i<k;i++) compare.push_back('J'); for(int i=0;i<k;i++) compare.push_back('O'); for(int i=0;i<k;i++) compare.push_back('I'); //deb(compare); if(isSubSequence(compare,s,m,compare_size)){ cout<<compare_size-m; } else cout<<"-1"; /*for(int i=0;i<f.size();i++){ cout<<f[i]; }*/ return(0); }

컴파일 시 표준 에러 (stderr) 메시지

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:43:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for(int i=0;i<s.size();i++) f.push_back(s[i]);
      |                 ~^~~~~~~~~
ho_t2.cpp:72:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i=0;i<f.size();i++){
      |                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...