Submission #947669

#TimeUsernameProblemLanguageResultExecution timeMemory
947669veljkoJJOOII 2 (JOI20_ho_t2)C++17
0 / 100
2 ms600 KiB
/*****from dust I have come, dust I will be*****/ #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long #define forn(i,n) for(int i=0;i<n;i++) int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 }; int ceil_div(int a, int b) {return a % b == 0 ? a / b : a / b + 1;} const int MOD = 1000000007; //const int MOD = 998244353; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key /* int k = A.order_of_key(p[i].second); A.erase(A.find_by_order(k)); erase element from pbds multiset */ void solve(){ int k,n; cin >> n>> k; string s; cin >> s; int ans = 1e18; vector<int>j, o, i; forn(x,n){ if (s[x] == 'J') j.push_back(x); else if (s[x] == 'O') o.push_back(x); else i.push_back(x); } int p1 = 0, p2 = k-1, x = 0; while (p2 < (int)j.size()){ x = (p2 - p1 + 1)-k; auto it = upper_bound(o.begin(), o.end(), j[p2]); int lo = it - o.begin(); int ro = lo + (k - 1); if (ro >= (int)o.size()){ p1++; p2++; continue;; } x += (ro - lo + 1) - k; it = upper_bound(i.begin(), i.end(), o[ro]); int li = it - i.begin(); int ri = li + (k - 1); if (ri >= (int)i.size()){ p1++; p2++; continue;; } x += (ri - li + 1) - k; //cout <<i[ri]-j[p1]+1 - k*3<<'\n'; ans = min(ans, (i[ri]-j[p1]+1 - k*3)); // cout <<j[p1]<<' '<<j[p2]<<'\n'; // cout <<o[lo]<<' '<<o[ro]<<'\n'; // cout <<i[li]<<' '<<i[ri]<<'\n'; p1++; p2++; } if (ans == 1e18) ans = -1; cout <<ans<<'\n'; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; //cin >>t; for (int i=1;i<=t;i++){ solve(); } return 0; }

Compilation message (stderr)

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