Submission #245413

# Submission time Handle Problem Language Result Execution time Memory
245413 2020-07-06T11:01:37 Z kevlee JJOOII 2 (JOI20_ho_t2) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
//priority_queue <int, vector <int>, greater <int> > pq;
int n, m, k, x, y, sum, cnt, ans = inf, a[200005], b[200005], c[200005];
string s;
int jn, on, in;
bool found;
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k >> s;
  FOR(i, 0, n-1) {
    if (s[i] == 'J') {
      a[jn++] = i;
    } else if (s[i] == 'O') {
      b[on++] = i;
    } else {
      c[in++] = i;
    }
  } 
  FOR(i, 0, jn-1) {
    if (i + k - 1 >= jn) break;
    int pos = upper_bound(b, b+on, a[i+k-1]) - b;
    if (pos == on) break;
    if (pos + k - 1 >= on) break;
    pos = upper_bound(c, c+in, b[pos+k-1]) - c;
    if (pos == in) break;
    pos = c[pos+k-1];
    found = true;
    ans = min(ans, pos - a[i] + 1 - 3 * k);
  }
  if (!found) cout << "-1" << endl;
  else cout << ans << endl;
  return 0;
}

Compilation message

ho_t2.cpp:29:5: error: 'int jn' redeclared as different kind of symbol
 int jn, on, in;
     ^~
In file included from /usr/include/features.h:367:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533,
                 from /usr/include/c++/7/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from ho_t2.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:249:1: note: previous declaration 'double jn(int, double)'
 __MATHCALL (jn,, (int, _Mdouble_));
 ^
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:38:11: warning: ISO C++ forbids incrementing a pointer of type 'double (*)(int, double) noexcept' [-Wpointer-arith]
       a[jn++] = i;
           ^~
ho_t2.cpp:38:11: error: lvalue required as increment operand
ho_t2.cpp:45:15: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   FOR(i, 0, jn-1) {
             ~~^~
ho_t2.cpp:24:46: note: in definition of macro 'FOR'
 #define FOR(i, a, b) for (int i = (a); i <= (b); i++)
                                              ^
ho_t2.cpp:24:47: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
 #define FOR(i, a, b) for (int i = (a); i <= (b); i++)
                                               ^
ho_t2.cpp:45:3: note: in expansion of macro 'FOR'
   FOR(i, 0, jn-1) {
   ^~~
ho_t2.cpp:46:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
     if (i + k - 1 >= jn) break;
                      ^~