結果
問題 | No.2553 Holidays |
ユーザー | Lê Hoàng Ngô |
提出日時 | 2024-07-02 12:36:49 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,658 bytes |
コンパイル時間 | 1,698 ms |
コンパイル使用メモリ | 179,268 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-02 12:36:53 |
合計ジャッジ時間 | 3,205 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 3 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | WA | - |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 3 ms
5,376 KB |
testcase_21 | AC | 3 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 3 ms
5,376 KB |
testcase_25 | AC | 3 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 3 ms
5,376 KB |
testcase_28 | AC | 3 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 1 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 1 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 2 ms
5,376 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 1 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 KB |
testcase_44 | AC | 1 ms
5,376 KB |
testcase_45 | AC | 2 ms
5,376 KB |
testcase_46 | AC | 2 ms
5,376 KB |
testcase_47 | AC | 1 ms
5,376 KB |
testcase_48 | WA | - |
testcase_49 | AC | 1 ms
5,376 KB |
testcase_50 | AC | 2 ms
5,376 KB |
testcase_51 | AC | 1 ms
5,376 KB |
testcase_52 | AC | 1 ms
5,376 KB |
testcase_53 | AC | 2 ms
5,376 KB |
testcase_54 | AC | 2 ms
5,376 KB |
testcase_55 | AC | 1 ms
5,376 KB |
testcase_56 | AC | 2 ms
5,376 KB |
testcase_57 | AC | 1 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(); } }