답안 #400045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400045 2021-05-07T08:48:47 Z SavicS JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
11 ms 3192 KB
#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] <= n; 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

**/

Compilation message

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];
      |                ~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 268 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 328 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 268 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 11 ms 2976 KB Output is correct
37 Correct 10 ms 3092 KB Output is correct
38 Correct 10 ms 3092 KB Output is correct
39 Correct 10 ms 3092 KB Output is correct
40 Correct 10 ms 3092 KB Output is correct
41 Correct 11 ms 3092 KB Output is correct
42 Correct 10 ms 3092 KB Output is correct
43 Correct 6 ms 2252 KB Output is correct
44 Correct 7 ms 2496 KB Output is correct
45 Correct 9 ms 3092 KB Output is correct
46 Correct 9 ms 3132 KB Output is correct
47 Correct 9 ms 3092 KB Output is correct
48 Correct 9 ms 3092 KB Output is correct
49 Correct 6 ms 2132 KB Output is correct
50 Correct 9 ms 3092 KB Output is correct
51 Correct 9 ms 3096 KB Output is correct
52 Correct 7 ms 2972 KB Output is correct
53 Correct 8 ms 3092 KB Output is correct
54 Correct 6 ms 3092 KB Output is correct
55 Correct 6 ms 3192 KB Output is correct
56 Correct 6 ms 3092 KB Output is correct