QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#659517 | #8058. Binary vs Ternary | ucup-team4992 | RE | 0ms | 0kb | C++14 | 1.4kb | 2024-10-19 20:32:22 | 2024-10-19 20:32:26 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2510, M = 10010;
void solve() {
vector<vector<int>> G(N), stk(N);
int id, d;
cin >> id >> d;
int n = id;
G[id].resize(d + 1);
vector<int> sure(N);
int sure_cnt = 0;
auto work = [&]() {
n = max(n, id);
G[id].resize(d + 1);
for (int i = 1; i <= d; i++) {
int& v = G[id][i];
if (v) continue;
cout << "! " << i << '\n';
cout.flush();
cin >> v >> d;
stk[v].push_back(id);
id = v;
return;
}
if (!sure[id]) {
sure[id]++;
sure_cnt++;
}
for (int i = 1; i <= d; i++) {
int& v = G[id][i];
if (v == stk[id].back()) {
stk[id].pop_back();
cout << "! " << i << '\n';
cout.flush();
cin >> v >> d;
id = v;
return;
}
}
};
while (sure_cnt < n) {
work();
}
cout << "! ";
for (int i = 1; i <= n; i++) {
for (int j = G[i].size() - 1; j >= 1; j--) {
int& v = G[i][j];
if (i < v) cout << i << ' ' << v << ' ';
}
}
cout << '\n';
string cr;
cin >> cr;
}
int main() {
int T;
cin >> T;
while (T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
3 1 111 110110 1101010 1111 111111
output:
! 1