Submission #1175018

#TimeUsernameProblemLanguageResultExecution timeMemory
1175018manuelalejandroJJOOII 2 (JOI20_ho_t2)C++20
0 / 100
0 ms324 KiB
#include <bits/extc++.h> #define int long long #define pb push_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define tam(x) (int)(x).size() #define endl '\n' #define sd second #define fs first #define maxs(x,y) (x = max(x,y)) #define mins(x,y) (x = min(x,y)) #define optmizar_io ios_base::sync_with_stdio(0); cin.tie(0); #define Setpre(n) cout << fixed <<setprecision(n) #define dbg(x) for(auto y: x) cout << y <<' '; cout << endl; #define dbg1(x) for(auto y: x) cout << y.first <<' '<< y.second << endl; #define dbg2(v) for(auto x: v) cout << x.a<< ' '<< x.b <<' '<< x.c << endl; const int MAX = 501; const int INF = 1e17; const int Mod = 1e9+7; const int zero = 0; const double eps = 1e-6; const double PI=acos(-1.0); const int mox[8] ={-1,1,0,0,-1,-1,1,1}; const int moy[8] ={0,0,-1,1,-1,1,-1,1}; using namespace std; using namespace __gnu_pbds; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; typedef vector<bool> vbol; typedef array<int, 3> arr; template <typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; void cases(string s){ #ifndef ONLINE_JUDGE if(tam(s) == 0) s = "1"; string a = s + ".in"; string b = s + ".out"; freopen(a.c_str(), "r", stdin); freopen(b.c_str(), "w", stdout); #endif } void _1() { int n, k; cin >> n >> k; vvi ar(3, vi(n + 10, 0)); string s; cin >> s; for(int i = 1; i <= n; i++) { for(int j = 0; j < 3; j++) ar[j][i] = ar[j][i - 1]; if(s[i - 1] == 'J') ar[0][i]++; else if(s[i - 1] == 'O') ar[1][i]++; else ar[2][i]++; } // for(int j = 0; j < 3; j++) // { // for(int i = 1; i <= n; i++) cout << ar[i][j] << " "; // cout << endl; // } int ans = INF, c = 0; auto it = lower_bound(all(ar[0]), 1) - ar[0].begin(); while(it <= n) // int t = 1; // while(t--) { auto j1 = lower_bound(all(ar[0]), ar[0][it] + k - 1) - ar[0].begin(); auto o1 = lower_bound(all(ar[1]), ar[1][j1] + 1) - ar[1].begin(); auto o2 = lower_bound(all(ar[1]), ar[1][o1] + k - 1) - ar[1].begin(); auto i1 = lower_bound(all(ar[2]), ar[2][o2] + 1) - ar[2].begin(); auto i2 = lower_bound(all(ar[2]), ar[2][i1] + k - 1) - ar[2].begin(); if(j1 > n or i1 > n or o1 > n or o2 > n or i1 > n or i2 > n); else mins(ans, (i2 - it + 1) - (3 * k)); it = lower_bound(all(ar[0]), ar[0][it] + 1) - ar[0].begin(); } if(ans == INF) ans = -1; cout << ans << endl; } int32_t main() { optmizar_io // cases(""); //start: //end: //tags: //difficulty: //comment: int T = 1; //cin >> T; while(T--) _1(); return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'void cases(std::string)':
ho_t2.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     freopen(a.c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen(b.c_str(), "w",  stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...