暴力100分 建议加强数据
  • 板块P1503 鬼子进村
  • 楼主YY_Z
  • 当前回复4
  • 已保存回复6
  • 发布时间2024/8/8 12:03
  • 上次更新2024/8/8 13:23:15
查看原帖
暴力100分 建议加强数据
245219
YY_Z楼主2024/8/8 12:03

稍微写快一点的暴力可以过

#include <bits/stdc++.h>

using namespace std;

const int MAX = 1e5 + 10;

int n, m;
bool room[MAX];
stack<int> last;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    char op;
    int x;
    room[0] = room[n + 1] = true;
    for (int i = 0; i < m; i++) {
        cin >> op;
        if (op == 'D') {
            cin >> x;
            room[x] = true;
            last.push(x);
        } else if (op == 'R') {
            if (!last.empty()) {
                room[last.top()] = 0;
                last.pop();
            }
        } else {
            cin >> x;
            if (room[x]) {
                cout << 0 << endl;
                continue;
            }
            int ans = 0;
            for (int now = x; !room[now]; now++) ans++;
            for (int now = x - 1; !room[now]; now--) ans++;
            cout << ans << "\n";
        }
    }
    return 0;
}

大概在超时的边缘测评记录 比较玄学,有的时候最后一个点就过不了测评记录

2024/8/8 12:03
加载中...