結果

問題 No.1943 消えたAGCT(1)
ユーザー forest3forest3
提出日時 2022-07-10 13:00:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 1,486 ms
コンパイル使用メモリ 170,540 KB
実行使用メモリ 27,060 KB
最終ジャッジ日時 2023-08-30 23:44:54
合計ジャッジ時間 3,837 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 214 ms
27,060 KB
testcase_10 AC 11 ms
4,376 KB
testcase_11 AC 12 ms
4,380 KB
testcase_12 AC 11 ms
4,376 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 35 ms
6,932 KB
testcase_16 AC 28 ms
6,136 KB
testcase_17 AC 29 ms
6,216 KB
testcase_18 AC 37 ms
7,316 KB
testcase_19 AC 38 ms
7,452 KB
testcase_20 AC 38 ms
7,276 KB
testcase_21 AC 38 ms
7,316 KB
testcase_22 AC 146 ms
19,344 KB
testcase_23 AC 145 ms
19,176 KB
testcase_24 AC 14 ms
4,376 KB
testcase_25 AC 14 ms
4,380 KB
testcase_26 AC 14 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	string s;
	cin >> n >> s;

	set<int> st;
	for( int i = 0; i < n; i++ ) {
		if( s[i] == 'A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T' ) st.insert( i );
	}
	int ans = 0;
	int last = -1;
	int del = 0;
	while( st.size() ) {
		int j = st.size() - 1;
		auto it = st.lower_bound( j );
		int a = *it - j + 1;
		if( last < 0 ) {
			last = *it;
			del += a;
		}
		else if( *it > last ) {
			int t = a;
			a -= del;
			del = t;
			last = *it;
		}
		else {
			last = *it;
			del += a;
		}
		ans += a;
		st.erase( it );
	}

	cout << ans << endl;
}
0