結果

問題 No.1943 消えたAGCT(1)
コンテスト
ユーザー nawawan
提出日時 2022-05-20 21:59:57
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,246 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 633 ms
コンパイル使用メモリ 106,484 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2026-06-26 03:31:52
合計ジャッジ時間 4,496 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int cnt = 0;
    set<char> s;
    s.insert('A');
    s.insert('C');
    s.insert('G');
    s.insert('T');
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')
            cnt++;
    }
    int ans = 0;
    int ind = cnt - 2;
    int rest = cnt;
    while (rest > 0)
    {
        bool f = false;
        for (int i = cnt - 1; i < N; i++)
        {
            f = true;
            ans++;
            if (s.count(S[i]))
            {
                cnt = i + 2;
                rest--;
                while (ind >= 0 && s.count(S[ind]))
                {
                    ans++;
                    rest--;
                    ind--;
                }
                break;
            }
        }
        if (!f)
        {
            while (ind >= 0)
            {
                if (s.count(S[ind]))
                {
                    rest--;
                }
                ind--;
                ans++;
            }
        }
    }
    cout << ans << endl;
}
0