結果
問題 | No.2553 Holidays |
ユーザー | Lê Hoàng Ngô |
提出日時 | 2024-07-02 12:34:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,655 bytes |
コンパイル時間 | 1,858 ms |
コンパイル使用メモリ | 177,376 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 12:34:41 |
合計ジャッジ時間 | 3,612 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 3 ms
5,376 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | AC | 2 ms
5,376 KB |
testcase_47 | AC | 2 ms
5,376 KB |
testcase_48 | WA | - |
testcase_49 | AC | 2 ms
5,376 KB |
testcase_50 | AC | 2 ms
5,376 KB |
testcase_51 | AC | 2 ms
5,376 KB |
testcase_52 | AC | 2 ms
5,376 KB |
testcase_53 | AC | 2 ms
5,376 KB |
testcase_54 | AC | 2 ms
5,376 KB |
testcase_55 | AC | 2 ms
5,376 KB |
testcase_56 | AC | 2 ms
5,376 KB |
testcase_57 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<=b;i++) #define rep_r(i,a,b) for(int i=a;i>=b;i--) #define each(a,x) for (auto& x : a) using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vl = vector<ll>; #define sz(x) int(x.size()) #define so(x) sort(all(x)) #define so_r(x) sort(all(x),greater<int>()) #define lb lower_bound #define ub upper_bound const char nl = '\n'; int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int bit_cnt(int x){ return __builtin_popcount(x); } ll bex(ll a, ll b, ll mod = 1e9 + 7){ll res = 1LL; while(b){ if (b&1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;} template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;} const int MOD = 998244353; const int N = 1e5 + 5; const ll INF = 1e16; vector<int> segments[6]; void solve(){ int n,m; cin >> n >> m; string s; cin >> s; s = "x" + s + "x"; for (int i = 0; i <= n + 1; i++){ if (s[i] == '-'){ int st_pos = i; char st = s[i-1]; while (s[i] == '-') i++; char ed = s[i]; int len = i - st_pos; if (st == ed) { if (st == 'x') { // type 0: xx with even length if (len % 2 == 0) segments[0].push_back(len); // type 1: xx with odd length else segments[1].push_back(len); } else { // type 2: oo with even length if (len % 2 == 0) segments[2].push_back(len); // type 3: oo with odd length else segments[3].push_back(len); } } else { if (len % 2 == 0) segments[4].push_back(len); // xo or ox with even length else segments[5].push_back(len); // xo or ox with odd length } } } int ans = 0; for (int i = 1; i <= n; i++) ans += s[i] == 'o'; so(segments[3]); each(segments[3], seg) { cout<<"oo: "<<seg<<nl; while (m && seg > 1){ m--; seg -= 2; ans += 2; } if (seg==1) ans++; } each(segments[2], seg) { while (m && seg > 0) { m--; seg -= 2; ans += 2; } } int extra = 0; each(segments[4], seg) { while (m && seg > 0) { m--; seg -= 2; ans += 2; } } each(segments[5], seg) { while (m && seg > 1) { m--; seg -= 2; ans += 2; } if (seg==1) extra++; } so_r(segments[1]); each(segments[1], seg) { if (seg == 1) { extra++; continue; } if (m) m--, ans++, seg--; if (m) m--, ans++, seg--; while (m && seg > 1){ m--; seg -= 2; ans += 2; } if (seg==1) ans++; } so_r(segments[0]); each(segments[0], seg) { if (seg == 2) { extra += 2; continue; } if (m) m--, ans++, seg--; while (m && seg > 1) { m--; seg -= 2; ans += 2; } if (seg==1) extra++; } ans += min(extra, m); cout<<ans<<nl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--){ solve(); } }