foo.cc: In function 'int dfs(const std::vector<int>&)': foo.cc:32:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 32 | if (c.index >= tree.size() || c.signal <= 0 || tree[c.index] == 0) { | ~~~~~~~~^~~~~~~~~~~~~~
Syncing testdata, please wait...
| # | 状态 分数 | 耗时 | 内存占用 |
|---|---|---|---|
| (1) | Accepted 100 | ||
| #1 | Accepted | 1ms | 504 KiB |
| #2 | Accepted | 1ms | 392 KiB |
| #3 | Accepted | 1ms | 504 KiB |
| #4 | Accepted | 1ms | 624 KiB |
| #5 | Accepted | 1ms | 504 KiB |
| #6 | Accepted | 3ms | 768 KiB |
| #7 | Accepted | 3ms | 816 KiB |
| #8 | Accepted | 3ms | 812 KiB |
| #9 | Accepted | 1ms | 588 KiB |
| #10 | Accepted | 1ms | 576 KiB |
| #11 | Accepted | 1ms | 532 KiB |
| #12 | Accepted | 1ms | 512 KiB |
| #13 | Accepted | 2ms | 536 KiB |
| #14 | Accepted | 3ms | 820 KiB |
| #15 | Accepted | 2ms | 692 KiB |
| #16 | Accepted | 1ms | 576 KiB |
| #17 | Accepted | 1ms | 408 KiB |
| #18 | Accepted | 2ms | 688 KiB |
| #19 | Accepted | 2ms | 624 KiB |
| #20 | Accepted | 1ms | 616 KiB |
| #21 | Accepted | 2ms | 532 KiB |
| #22 | Accepted | 1ms | 504 KiB |
| #23 | Accepted | 3ms | 816 KiB |
| #24 | Accepted | 3ms | 824 KiB |
| #25 | Accepted | 4ms | 760 KiB |
代码
#include <bits/stdc++.h>
using namespace std;
struct NodeState {
int index;
int length;
int signal;
};
int cs(int type, int signal) {
if (type == 0) return 0;
if (type == 2) return 15;
if (type == 3) return signal - 1;
if (type >= 4 && type <= 7) {
int boost = 0;
if (type == 4) boost = 0;
else if (type == 5) boost = 1;
else if (type == 6) boost = 2;
else if (type == 7) boost = 4;
return (signal + boost) - 1;
}
return signal;
}
int dfs(const vector<int>& tree) {
if (tree.empty() || tree[0] != 1) {
return 0;
}
int max_l = 0;
stack<NodeState> stk;
stk.push({0, 0, 15});
while (!stk.empty()) {
NodeState c = stk.top();
stk.pop();
if (c.index >= tree.size() || c.signal <= 0 || tree[c.index] == 0) {
continue;
}
int new_s = cs(tree[c.index], c.signal);
int new_l = c.length + 1;
if (new_l > max_l) {
max_l = new_l;
}
if (new_s > 0) {
stk.push({2 * c.index + 2, new_l, new_s});
stk.push({2 * c.index + 1, new_l, new_s});
}
}
return max_l;
}
int main() {
freopen ("redstone.in","r",stdin);
freopen ("redstone.out","w",stdout);
int n;
cin >> n;
vector<int> tree(n);
for (int i = 0; i < n; i++) {
cin >> tree[i];
}
int result = dfs(tree);
cout << result << endl;
fclose (stdin);
fclose (stdout);
return 0;
}
信息
- 递交者
- 题目
- 237 [Sleeping Cup #10] Signal Traversal
- 语言
- C++14(O2)
- 代码长度
- 1.3 KiB
- 递交时间
- 2026-3-27 21:22:40
- 评测时间
- 2026-3-27 21:22:44
- 分数
- 100
- 总耗时
- 44ms
- 峰值时间
- 4ms
- 峰值内存
- 824 KiB