結果
| 問題 |
No.3061 Cut and Maximums
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-14 22:03:52 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,060 bytes |
| コンパイル時間 | 2,783 ms |
| コンパイル使用メモリ | 104,516 KB |
| 実行使用メモリ | 14,040 KB |
| 最終ジャッジ日時 | 2025-03-14 22:04:09 |
| 合計ジャッジ時間 | 5,363 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 21 |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;
class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; }
bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }
int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }
int solve(int N, int[] P, string S) {
if (S == 'W'.repeat(N).array) return 0;
if (S[N - 1] == 'W') return -1;
foreach (i; 0 .. N) if (P[i] == N - 1) {
P = P[0 .. i] ~ P[i .. N];
break;
}
for (int i = 0, j = 0; i < N; i = j) {
for (; j < N && S[P[i]] == S[P[j]]; ++j) {}
if (S[P[i]] == 'W') {
int mx = -1;
foreach (k; i .. j) chmax(mx, P[k]);
if (P[i - 1] < mx && mx > P[j % N]) return 2;
}
}
return 1;
}
void main() {
/*
debug {{
foreach (N; 1 .. 6 + 1) {
auto P = iota(N).array;
do {
auto can = new bool[1 << N];
foreach (s; 0 .. N) foreach (h; 0 .. 1 << (N-1)) {
int[] cuts;
cuts ~= s;
foreach (i; 1 .. N) if (h >> (i-1) & 1) cuts ~= (s + i);
const len = cast(int)(cuts.length);
cuts ~= (s + N);
int q;
foreach (j; 0 .. len) {
int mx = -1;
foreach (i; cuts[j] .. cuts[j + 1]) chmax(mx, P[i % N]);
q |= 1 << mx;
}
can[q] = true;
}
auto dp = new int[1 << N];
dp[] = -1;
dp[0] = 0;
foreach (p; 0 .. 1 << N) if (dp[p] >= 0) {
foreach (q; 0 .. 1 << N) if (can[q]) {
const pp = p | q;
if (!~dp[pp] || dp[pp] > dp[p] + 1) dp[pp] = dp[p] + 1;
}
}
writeln(P, ": ");
foreach (q; 0 .. 1 << N) write(can[q] ? 1 : 0);
writeln(": ", dp);
assert(dp.maxElement <= 3);
foreach (p; 1 << (N-1) .. 1 << N) assert(~dp[p]);
} while (P.nextPermutation);
}
}}
*/
try {
for (; ; ) {
const N = readInt;
auto P = new int[N];
foreach (i; 0 .. N) {
P[i] = readInt - 1;
}
const S = readToken;
const ans = solve(N, P, S);
writeln(ans);
}
} catch (EOFException e) {
}
}