結果

問題 No.2073 Concon Substrings (Swap Version)
ユーザー みここ
提出日時 2022-12-13 00:04:11
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 67,916 KB
最終ジャッジ日時 2025-02-09 10:40:07
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int d[3][3];

int main()
{
    int n;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n * 3; i++)
    {
        if (s[i] == 'c')
        {
            d[i % 3][0]++;
        }
        if (s[i] == 'o')
        {
            d[i % 3][1]++;
        }
        if (s[i] == 'n')
        {
            d[i % 3][2]++;
        }
    }
    int e[3] = {n, n, n};
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            e[i] = min(e[i], d[(i + j) % 3][j]);
        }
    }
    int ans = e[0] + e[1] + e[2];
    if (ans == n)
    {
        if (e[0] < n)
        {
            ans--;
        }
    }
    cout << ans << endl;
}
0