제출 #400043

#제출 시각아이디문제언어결과실행 시간메모리
400043SavicSJJOOII 2 (JOI20_ho_t2)C++14
0 / 100
1 ms328 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ff(i,a,b) for(int i=a;i<=b;i++) #define fb(i,b,a) for(int i=b;i>=a;i--) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int,int> pii; const int maxn = 200005; const int inf = 1e9 + 5; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) int n, K; string s; int ptr[4]; int pref[maxn][3]; int f(char C){ if(C == 'J')return 1; if(C == 'O')return 2; if(C == 'I')return 3; assert(false); } int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> n >> K >> s; s = ' ' + s; ff(i,1,n){ ff(j,1,3)pref[i][j] = pref[i - 1][j]; pref[i][f(s[i])] += 1; } int rez = inf; for(ptr[0] = 0; ptr[0] <= 1; ptr[0] += 1){ ff(i,1,3){ while (ptr[i] < ptr[i - 1] || (ptr[i] <= n && pref[ptr[i]][i] - pref[ptr[i - 1]][i] < K)){ ptr[i]++; } } bool ok = 1; ff(i,1,3)ok &= (ptr[i] <= n && pref[ptr[i]][i] - pref[ptr[i - 1]][i] >= K); if(ok)rez = min(rez, ptr[3] - ptr[0] - 3 * K); } cout << (rez == inf ? -1 : rez) << endl; return 0; } /** 9 3 JJJOOOIII // probati bojenje sahovski ili slicno **/

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

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:49:42: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations]
   49 |       ff(j,1,3)pref[i][j] = pref[i - 1][j];
      |                             ~~~~~~~~~~~~~^
ho_t2.cpp:11:32: note: within this loop
   11 | #define ff(i,a,b) for(int i=a;i<=b;i++)
......
   49 |       ff(j,1,3)pref[i][j] = pref[i - 1][j];
      |          ~~~~~                  
ho_t2.cpp:49:7: note: in expansion of macro 'ff'
   49 |       ff(j,1,3)pref[i][j] = pref[i - 1][j];
      |       ^~
ho_t2.cpp:49:42: warning: array subscript 3 is above array bounds of 'int [3]' [-Warray-bounds]
   49 |       ff(j,1,3)pref[i][j] = pref[i - 1][j];
      |                             ~~~~~~~~~~~~~^
ho_t2.cpp:49:25: warning: array subscript 3 is above array bounds of 'int [3]' [-Warray-bounds]
   49 |       ff(j,1,3)pref[i][j] = pref[i - 1][j];
      |                ~~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...