結果

問題 No.1943 消えたAGCT(1)
ユーザー forest3
提出日時 2022-07-10 13:00:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 1,830 ms
コンパイル使用メモリ 166,204 KB
実行使用メモリ 27,068 KB
最終ジャッジ日時 2025-01-02 23:46:23
合計ジャッジ時間 4,164 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

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