結果
問題 | No.2924 <===Super Spaceship String===> |
ユーザー |
|
提出日時 | 2024-10-12 15:21:50 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 1,487 bytes |
コンパイル時間 | 4,809 ms |
コンパイル使用メモリ | 169,600 KB |
実行使用メモリ | 14,384 KB |
最終ジャッジ日時 | 2024-10-16 17:54:20 |
合計ジャッジ時間 | 5,576 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
import std; void main () { string S = readln.chomp; // <のペアを先に見つける // -> あるペアを消せる条件は、ペアの間にあるペアがすべて消える かつ ペアの間に=が1以上存在 const int N = S.length.to!int; auto idx = new int[](0); auto pair = new int[](N); auto deleted = new bool[](N); pair[] = -1; foreach_reverse (i; 0..N) { if (S[i] == '<') { if (0 < idx.length) { pair[i] = idx[$ - 1]; idx.length--; } } if (S[i] == '>') { idx ~= i; } } // うしろから見ていく foreach_reverse (i; 0..N) { if (pair[i] == -1) continue; bool res = false; foreach (ref j; i + 1..pair[i]) { if (S[j] == '=') res = true; if (pair[j] == -1) continue; if (!deleted[j]) { res = false; break; } else { j = pair[j]; } } deleted[i] = res; } // 前から見ていく int ans = N; foreach (ref i; 0..N) { if (deleted[i]) { ans -= pair[i] - i + 1; i = pair[i]; } } writeln(ans); } void read (T...) (string S, ref T args) { import std.conv : to; import std.array : split; auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }