Submission #838007

#TimeUsernameProblemLanguageResultExecution timeMemory
838007vjudge1JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
6 ms3288 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define pii pair <int, int> #define pb push_back #define mp make_pair #define dbg puts("dbg"); #define outp(x) cout << #x << " = " << (x) << endl #define all(x) (x).begin(), (x).end() #define test int t; cin >> t; while(t--){solve();} #define MOD 998244353 int fpb(int a,int b){if(b == 0){return a;}return fpb(b, a%b);} int kpk(int a,int b){return (a*b)/fpb(a, b);} int n, k, indeksJ, indeksO, indeksI, mini = 1e9; string S; vector <int> J, O, I; void solve(){ cin >> n >> k; cin >> S; for(int i=0; i<S.length(); i++){ if(S[i] == 'J') J.pb(i); else if(S[i] == 'O') O.pb(i); else I.pb(i); } while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){ int awalJ, awalO, awalI; int akhirJ, akhirO, akhirI; if(indeksJ+k-1 >= J.size()) break; awalJ = J[indeksJ]; akhirJ = J[indeksJ+k-1]; while(O[indeksO] < akhirJ) indeksO++; if(indeksO+k-1 >= O.size()) break; awalO = O[indeksO]; akhirO = O[indeksO+k-1]; while(I[indeksI] < akhirO) indeksI++; if(indeksI+k-1 >= I.size()) break; awalI = I[indeksI]; akhirI = I[indeksI+k-1]; int hapus = akhirI - awalJ + 1 - 3*k; mini = min(mini, hapus); indeksJ++; } cout << ((mini != 1e9)?mini:-1) << endl; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); solve(); return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:23:19: 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]
   23 |     for(int i=0; i<S.length(); i++){
      |                  ~^~~~~~~~~~~
ho_t2.cpp:28:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){
      |           ~~~~~~~~^~~~~~~~~~
ho_t2.cpp:28:41: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){
      |                                 ~~~~~~~~^~~~~~~~~~
ho_t2.cpp:28:63: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while(indeksJ < J.size() && indeksO < O.size() && indeksI < I.size()){
      |                                                       ~~~~~~~~^~~~~~~~~~
ho_t2.cpp:31:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         if(indeksJ+k-1 >= J.size()) break;
      |            ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:35:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         if(indeksO+k-1 >= O.size()) break;
      |            ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:39:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if(indeksI+k-1 >= I.size()) break;
      |            ~~~~~~~~~~~~^~~~~~~~~~~
ho_t2.cpp:29:20: warning: variable 'awalO' set but not used [-Wunused-but-set-variable]
   29 |         int awalJ, awalO, awalI;
      |                    ^~~~~
ho_t2.cpp:29:27: warning: variable 'awalI' set but not used [-Wunused-but-set-variable]
   29 |         int awalJ, awalO, awalI;
      |                           ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...