提出 #69735866
ソースコード 拡げる
#include <stdio.h>
#include <inttypes.h>
int64_t ztt(int64_t x) {
return x < 0 ? -x : x;
}
int64_t Rt, Ct, Ra, Ca;
int64_t N;
int M, L;
char S[114514];
int64_t A[114514];
char T[114514];
int64_t B[114514];
int main(void) {
int i;
int tpos = 0, apos = 0;
int64_t ans = 0;
if (scanf("%" SCNd64 "%" SCNd64 "%" SCNd64 "%" SCNd64, &Rt, &Ct, &Ra, &Ca) != 4) return 1;
if (scanf("%" SCNd64 "%d%d", &N, &M, &L) != 3) return 1;
for (i = 0; i < M; i++) {
char buf[4];
if (scanf("%3s%" SCNd64, buf, &A[i]) != 2) return 1;
S[i] = *buf;
}
for (i = 0; i < L; i++) {
char buf[4];
if (scanf("%3s%" SCNd64, buf, &B[i]) != 2) return 1;
T[i] = *buf;
}
while (tpos < M && apos < L) {
int Rtd = (S[tpos] == 'D') - (S[tpos] == 'U');
int Ctd = (S[tpos] == 'R') - (S[tpos] == 'L');
int Rad = (T[apos] == 'D') - (T[apos] == 'U');
int Cad = (T[apos] == 'R') - (T[apos] == 'L');
int64_t count = A[tpos];
if (B[apos] < count) count = B[apos];
A[tpos] -= count;
B[apos] -= count;
if (A[tpos] <= 0) tpos++;
if (B[apos] <= 0) apos++;
if (Ct == Ca && Rtd * Rad < 0) {
/* 縦方向に向かい合う */
int64_t z = ztt(Rt - Ra);
if (z > 0 && z % 2 == 0 && z <= count * 2 && (Rt < Ra) == (Rtd > 0)) ans++;
} else if (Rt == Ra && Ctd * Cad < 0) {
/* 横方向に向かい合う */
int64_t z = ztt(Ct - Ca);
if (z > 0 && z % 2 == 0 && z <= count * 2 && (Ct < Ca) == (Ctd > 0)) ans++;
} else if (Rt == Ra && Ct == Ca && Rtd == Rad && Ctd == Cad) {
/* 重なって動く */
ans += count;
} else if (Rtd != 0 && Cad != 0) {
/* 垂直方向に出会う (1) */
int64_t t = (Ra - Rt) / Rtd;
if (t > 0 && t <= count && Ca + Cad * t == Ct) ans++;
} else if (Ctd != 0 && Rad != 0) {
/* 垂直方向に出会う (2) */
int64_t t = (Ca - Ct) / Ctd;
if (t > 0 && t <= count && Ra + Rad * t == Rt) ans++;
}
Rt += Rtd * count;
Ct += Ctd * count;
Ra += Rad * count;
Ca += Cad * count;
}
printf("%" PRId64 "\n", ans);
return 0;
}
/*
0 0 0 2
10 1 1
L 10
R 10
同じ行に居て、遠ざかるパターン
当然重ならず、0 が出力されるべきである
しかし、「同じ行」「列方向の逆方向に移動」「2者の距離が移動距離の2倍以下」
の判定だけだと、1 になってしまう
*/
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - RLE Moving |
| ユーザ | mikecat |
| 言語 | C (gcc 12.2.0) |
| 得点 | 425 |
| コード長 | 2378 Byte |
| 結果 | AC |
| 実行時間 | 28 ms |
| メモリ | 3500 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 425 / 425 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
| All | random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| random_01.txt | AC | 28 ms | 3368 KiB |
| random_02.txt | AC | 18 ms | 2820 KiB |
| random_03.txt | AC | 6 ms | 2448 KiB |
| random_04.txt | AC | 11 ms | 2324 KiB |
| random_05.txt | AC | 5 ms | 1936 KiB |
| random_06.txt | AC | 24 ms | 3388 KiB |
| random_07.txt | AC | 24 ms | 3416 KiB |
| random_08.txt | AC | 24 ms | 3340 KiB |
| random_09.txt | AC | 25 ms | 3364 KiB |
| random_10.txt | AC | 25 ms | 3476 KiB |
| random_11.txt | AC | 25 ms | 3472 KiB |
| random_12.txt | AC | 26 ms | 3488 KiB |
| random_13.txt | AC | 26 ms | 3480 KiB |
| random_14.txt | AC | 25 ms | 3500 KiB |
| random_15.txt | AC | 26 ms | 3396 KiB |
| random_16.txt | AC | 25 ms | 3496 KiB |
| random_17.txt | AC | 28 ms | 3404 KiB |
| random_18.txt | AC | 28 ms | 3488 KiB |
| random_19.txt | AC | 27 ms | 3488 KiB |
| random_20.txt | AC | 27 ms | 3468 KiB |
| sample_01.txt | AC | 0 ms | 1588 KiB |
| sample_02.txt | AC | 0 ms | 1588 KiB |
| sample_03.txt | AC | 0 ms | 1720 KiB |
| sample_04.txt | AC | 1 ms | 1640 KiB |