답안 #201571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201571 2020-02-11T06:50:00 Z theStaticMind JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
23 ms 5240 KB
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
int lower(vector<int>& arr, int x){
      int l = 0;
      int r = (int)arr.size() - 1;
      int ret = -1;
      while(l <= r){
            int mid = (l + r) / 2;
            if(arr[mid] >= x){
                  r = mid - 1;
                  ret = mid;
            }
            else l = mid + 1;
      }
      return ret;
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
//      freopen("q.gir","r",stdin);
//      freopen("q.cik","w",stdout);
      int n, k, ans = INF;
      cin >> n >> k;
      string s;
      cin >> s;
      vector<int> arr(1, -1);
      vector<int> data[3];
      for(int i = 0; i < n; i++){
            if(s[i] == 'J')arr.pb(0);
            if(s[i] == 'O')arr.pb(1);
            if(s[i] == 'I')arr.pb(2);
      }
      for(int i = 1; i <= n; i++){
            data[arr[i]].pb(i);
      }
      for(int i = 0; i + k - 1 < data[0].size(); i++){
            int sj = i;
            int ej = i + k - 1;
            int so = lower(data[1], data[0][ej]);
            if(so == -1 || so + k - 1 >= data[1].size())continue;
            int eo = so + k - 1;
            int si = lower(data[2], data[1][eo]);
            if(si == -1 || si + k - 1 >= data[2].size())continue;
            int ei = si + k - 1;
            ans = min(ans, data[2][ei] - data[0][i] + 1 - 3 * k);
      }
      if(ans == INF)cout << -1;
      else cout << ans;
}

Compilation message

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:43:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i = 0; i + k - 1 < data[0].size(); i++){
                      ~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:47:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(so == -1 || so + k - 1 >= data[1].size())continue;
                            ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ho_t2.cpp:50:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(si == -1 || si + k - 1 >= data[2].size())continue;
                            ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ho_t2.cpp:44:17: warning: unused variable 'sj' [-Wunused-variable]
             int sj = i;
                 ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 248 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 248 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 380 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 248 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 380 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 18 ms 3952 KB Output is correct
37 Correct 21 ms 5236 KB Output is correct
38 Correct 21 ms 5240 KB Output is correct
39 Correct 19 ms 5236 KB Output is correct
40 Correct 18 ms 5240 KB Output is correct
41 Correct 18 ms 5236 KB Output is correct
42 Correct 20 ms 5240 KB Output is correct
43 Correct 11 ms 3244 KB Output is correct
44 Correct 13 ms 3572 KB Output is correct
45 Correct 16 ms 5236 KB Output is correct
46 Correct 16 ms 5236 KB Output is correct
47 Correct 16 ms 5236 KB Output is correct
48 Correct 16 ms 5236 KB Output is correct
49 Correct 13 ms 3188 KB Output is correct
50 Correct 23 ms 5236 KB Output is correct
51 Correct 16 ms 5232 KB Output is correct
52 Correct 12 ms 4084 KB Output is correct
53 Correct 13 ms 5236 KB Output is correct
54 Correct 13 ms 4724 KB Output is correct
55 Correct 12 ms 4724 KB Output is correct
56 Correct 11 ms 4724 KB Output is correct