Submission #230632

# Submission time Handle Problem Language Result Execution time Memory
230632 2020-05-10T16:32:51 Z AlexLuchianov JJOOII 2 (JOI20_ho_t2) C++14
1 / 100
2000 ms 384 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <set>

using namespace std;

using ll = long long;

int const nmax = 200000;

char s[5 + nmax];
vector<int> sets[3];

int lowerthan(vector<int> &v, int target){
  int x = 0;
  for(int jump = (1 << 20); 0 < jump; jump--)
    if(x + jump < v.size() && v[x + jump] <= target)
      x += jump;
  return x;
}

int eval(int n, int k, int stop){
  int init = stop;

  for(int h = 2; 0 <= h; h--){
    int pos = lowerthan(sets[h], stop);
    if(pos < k)
      return nmax * 2;
    stop = sets[h][pos - k + 1] - 1;
  }
  return n - 3 * k - (n - init) - stop;
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  sets[0].push_back(0);
  sets[1].push_back(0);
  sets[2].push_back(0);

  for(int i = 1; i <= n; i++) {
    char ch;
    cin >> ch;
    if(ch == 'J')
      sets[0].push_back(i);
    else if(ch == 'O')
      sets[1].push_back(i);
    else
      sets[2].push_back(i);
  }

  int result = nmax * 2;
  for(int i = 1; i < sets[2].size(); i++)
    result = min(result, eval(n, k, sets[2][i]));

  if(result < nmax * 2)
    cout << result;
  else
    cout << -1;
  return 0;
}

Compilation message

ho_t2.cpp: In function 'int lowerthan(std::vector<int>&, int)':
ho_t2.cpp:20:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(x + jump < v.size() && v[x + jump] <= target)
        ~~~~~~~~~^~~~~~~~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:60:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 1; i < sets[2].size(); i++)
                  ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 384 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Correct 29 ms 384 KB Output is correct
4 Correct 23 ms 384 KB Output is correct
5 Correct 34 ms 384 KB Output is correct
6 Correct 19 ms 384 KB Output is correct
7 Correct 15 ms 384 KB Output is correct
8 Correct 16 ms 384 KB Output is correct
9 Correct 24 ms 384 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 10 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 23 ms 384 KB Output is correct
14 Correct 13 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 384 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Correct 29 ms 384 KB Output is correct
4 Correct 23 ms 384 KB Output is correct
5 Correct 34 ms 384 KB Output is correct
6 Correct 19 ms 384 KB Output is correct
7 Correct 15 ms 384 KB Output is correct
8 Correct 16 ms 384 KB Output is correct
9 Correct 24 ms 384 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 10 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 23 ms 384 KB Output is correct
14 Correct 13 ms 384 KB Output is correct
15 Execution timed out 2080 ms 384 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 384 KB Output is correct
2 Correct 12 ms 384 KB Output is correct
3 Correct 29 ms 384 KB Output is correct
4 Correct 23 ms 384 KB Output is correct
5 Correct 34 ms 384 KB Output is correct
6 Correct 19 ms 384 KB Output is correct
7 Correct 15 ms 384 KB Output is correct
8 Correct 16 ms 384 KB Output is correct
9 Correct 24 ms 384 KB Output is correct
10 Correct 12 ms 384 KB Output is correct
11 Correct 10 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 23 ms 384 KB Output is correct
14 Correct 13 ms 384 KB Output is correct
15 Execution timed out 2080 ms 384 KB Time limit exceeded
16 Halted 0 ms 0 KB -