Submission #682757

#TimeUsernameProblemLanguageResultExecution timeMemory
682757Paul_Liao_1457JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
10 ms2020 KiB
//記得跳題 #include<iostream> #include<array> #include<vector> #include<string> #include<algorithm> #include<set> #include<queue> #include<stack> #include<math.h> #include<map> #include<unordered_map> #include<cstring> #include<iomanip> #include<bitset> #include<tuple> #define ll long long #define LL __int128_t #define DB double #define FOR(i,a,b) for(int i=a;i<b;i++) #define REP(i,a,b) for(int i=a;i>=b;i--) #define pb push_back #define mp make_pair #define INF (ll)(1e9) #define MOD (ll)(1e9+7) #define F first #define S second #define endl "\n" #define AC ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; template<class T> using PQ=priority_queue<T,vector<T>,less<T> >; void file(){ freopen("/Users/liaoyunyang/Desktop/meta_in.txt","r",stdin); freopen("/Users/liaoyunyang/Desktop/meta_out.txt","w",stdout); } int a[200005],b[200005],init[200005],pre[200005],suf[200005]; map<int,int> ans; signed main(){ AC; vector<int> J,O,I; int n,k; cin>>n>>k; string s; cin>>s; FOR(i,0,n){ if(s[i]=='J') J.pb(i); else if(s[i]=='O') O.pb(i); else I.pb(i); } if(J.size()<k||O.size()<k||I.size()<k){ cout<<-1<<endl; return 0; } int ans=-1; for(int i=0;i<J.size()-k+1;i++){ int l=J[i],li=J[i+k-1]; int tmp=(int)(lower_bound(O.begin(),O.end(),li)-O.begin()); if(tmp+k>O.size()){ cout<<ans<<endl; return 0; } int oi=O[tmp+k-1]; int tmp2=(int)(lower_bound(I.begin(),I.end(),oi)-I.begin()); if(tmp2+k>I.size()){ cout<<ans<<endl; return 0; } int r=I[tmp2+k-1]; if(ans==-1){ ans=r-l+1-3*k; } else{ ans=min(ans,r-l+1-3*k); } } cout<<ans<<endl; } /* */

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:54:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     if(J.size()<k||O.size()<k||I.size()<k){
      |        ~~~~~~~~^~
ho_t2.cpp:54:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     if(J.size()<k||O.size()<k||I.size()<k){
      |                    ~~~~~~~~^~
ho_t2.cpp:54:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     if(J.size()<k||O.size()<k||I.size()<k){
      |                                ~~~~~~~~^~
ho_t2.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i=0;i<J.size()-k+1;i++){
      |                 ~^~~~~~~~~~~~~
ho_t2.cpp:61:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         if(tmp+k>O.size()){
      |            ~~~~~^~~~~~~~~
ho_t2.cpp:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         if(tmp2+k>I.size()){
      |            ~~~~~~^~~~~~~~~
ho_t2.cpp: In function 'void file()':
ho_t2.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("/Users/liaoyunyang/Desktop/meta_in.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen("/Users/liaoyunyang/Desktop/meta_out.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...