結果
| 問題 |
No.2073 Concon Substrings (Swap Version)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-16 21:49:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 683 bytes |
| コンパイル時間 | 2,221 ms |
| コンパイル使用メモリ | 171,096 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-21 19:06:31 |
| 合計ジャッジ時間 | 3,189 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 29 WA * 8 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:23:17: warning: 'msk' may be used uninitialized [-Wmaybe-uninitialized]
23 | msk ^= (1 << i);
| ~~~~^~~~~~~~~~~
main.cpp:18:18: note: 'msk' was declared here
18 | int ans = 0, msk;
| ^~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
string s; cin >> s;
vector<vector<int>> cnt(3, vector<int>(3));
string sub = "con";
for (int i = 0; i < 3 * n; i++) {
for (int j = 0; j < 3; j++) {
if (s[i] == sub[j]) {
cnt[(i + 3 - j) % 3][j]++;
}
}
}
int ans = 0, msk;
for (int i = 0; i < 3; i++) {
int x = *min_element(cnt[i].begin(), cnt[i].end());
if (x > 0) {
ans += x;
msk ^= (1 << i);
}
}
cout << min(ans, n - (__builtin_popcount(msk) > 1));
}