結果

問題 No.151 セグメントフィッシング
コンテスト
ユーザー 梧桐
提出日時 2026-03-23 23:49:21
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,206 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 962 ms
コンパイル使用メモリ 80,240 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2026-03-23 23:50:22
合計ジャッジ時間 59,877 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 5
other WA * 10 TLE * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

typedef long long LL;

struct Fish {
    int t, num, pos, heading; // 0:左,1:右
};

int n, q;
vector<Fish> fishes;

int main() {
    // freopen("fish.in", "r", stdin);
    // freopen("fish.out", "w", stdout);

    scanf("%d%d", &n, &q);
    for (int i = 1; i <= q; ++i) {
        int t, y, z;
        char ch;
            scanf(" %c%d%d%d", &ch, &t, &y, &z);
        if (ch == 'L') {
            fishes.push_back({ t, z, y, 0 });
        } else if (ch == 'R') {
            fishes.push_back({ t, z, y, 1 });
        } else {
            LL ans = 0LL;
            for (Fish f : fishes) {
                int left_t = t - f.t, heading = f.heading, pos = f.pos;
                while (left_t-- > 0) {
                    if (heading == 0) {
                        if (pos == 0) heading = 1;
                        else --pos;
                    } else {
                        if (pos == n - 1) heading = 0;
                        else ++pos;
                    }
                }
                if (y <= pos && pos < z) ans += f.num;
            }

            printf("%lld\n", ans);
        }
    }

    return 0;
}
0