結果
問題 |
No.2924 <===Super Spaceship String===>
|
ユーザー |
|
提出日時 | 2024-10-12 15:20:33 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,483 bytes |
コンパイル時間 | 5,019 ms |
コンパイル使用メモリ | 170,156 KB |
実行使用メモリ | 14,528 KB |
最終ジャッジ日時 | 2024-10-12 15:20:38 |
合計ジャッジ時間 | 5,101 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 8 WA * 3 |
ソースコード
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 (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)); } }