結果
| 問題 |
No.1951 消えたAGCT(2)
|
| コンテスト | |
| ユーザー |
naskya
|
| 提出日時 | 2022-04-29 17:45:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,197 bytes |
| コンパイル時間 | 2,564 ms |
| コンパイル使用メモリ | 150,600 KB |
| 最終ジャッジ日時 | 2025-01-28 22:20:59 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 8 |
ソースコード
#include <algorithm>
#include <array>
#include <cassert>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <string>
constexpr auto nchars = ('Z' - 'A') + 1;
int nAGCT(const std::array<int, nchars> a, const int rot) {
int res = 0;
for (const auto n : {'A', 'G', 'C', 'T'})
res += a[(((n - 'A' - rot) % nchars) + nchars) % nchars];
return res;
}
int main() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
assert(static_cast<int>(std::size(s)) == n);
assert(std::all_of(s.cbegin(), s.cend(), [](const char c) { return std::isupper(c); }));
std::array<int, nchars> cnt;
cnt.fill(0);
for (const char c : s)
++cnt[c - 'A'];
int rot = 0, res = 0;
__gnu_pbds::tree<int, __gnu_pbds::null_type, std::less<int>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> t;
for (int i = 0; i < n; ++i)
t.insert(i);
while (true) {
int left = nAGCT(cnt, rot);
if (left == 0) {
std::cout << res << '\n';
return 0;
}
auto iter = t.find_by_order(left - 1);
--cnt[s[*iter] - 'A'];
rot += cnt[s[*iter] - 'A'];
t.erase(iter);
++res;
}
}
naskya