Submission #1299028

#TimeUsernameProblemLanguageResultExecution timeMemory
1299028daotuankhoiJJOOII 2 (JOI20_ho_t2)C++20
100 / 100
188 ms2256 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define ll long long template <class T> bool ckmax(T &a, T b) { return a < b ? (a = b, true) : false; } template <class T> bool ckmin(T &a, T b) { return a > b ? (a = b, true) : false; } const int MAXN = 2e5 + 5; char a[MAXN]; vector<int> pos[3]; int main() { #define NAME "test" if (fopen(NAME".inp", "r")) { freopen(NAME".inp", "r", stdin); freopen(NAME".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; int id; if (a[i] == 'J') id = 0; else if (a[i] == 'O') id = 1; else id = 2; pos[id].emplace_back(i); } int ans = 1e9; for (int i = k - 1; i < (int)pos[2].size(); i++) { int x = pos[2][i - k + 1]; int pos1 = lower_bound(pos[1].begin(), pos[1].end(), x) - pos[1].begin() - 1; if (pos1 < k - 1) continue; x = pos[1][pos1 - k + 1]; int pos0 = lower_bound(pos[0].begin(), pos[0].end(), x) - pos[0].begin() - 1; if (pos0 < k - 1) continue; ckmin(ans, pos[2][i] - pos[0][pos0 - k + 1] + 1 - k * 3); cerr << pos[0][pos0 - k + 1] << ' ' << pos[2][i] << '\n'; } cout << (ans == 1e9 ? -1 : ans) << '\n'; return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...