社区讨论
暴力100分 建议加强数据
P1503鬼子进村参与者 3已保存回复 6
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lzkr96og
- 此快照首次捕获于
- 2024/08/08 12:05 2 年前
- 此快照最后确认于
- 2024/08/08 13:23 2 年前
稍微写快一点的暴力可以过
CPP#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;
}
回复
共 6 条回复,欢迎继续交流。
正在加载回复...