QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#330771 | #8056. Travel 2 | ucup-team133 | AC ✓ | 177ms | 5304kb | C++17 | 4.1kb | 2024-02-17 18:54:32 | 2024-04-09 19:11:18 |
Judging History
answer
// -fsanitize=undefined,
//#define _GLIBCXX_DEBUG
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <chrono>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i+=1)
#define rrep(i,n) for (int i=n-1;i>-1;i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << " )\n";
template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<class T>
bool chmin(T &a, T b){
if (a>b){
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b){
if (a<b){
a = b;
return true;
}
return false;
}
template<class T>
T sum(vec<T> x){
T res=0;
for (auto e:x){
res += e;
}
return res;
}
template<class T>
void printv(vec<T> x){
for (auto e:x){
cout<<e<<" ";
}
cout<<endl;
}
template<class T,class U>
ostream& operator<<(ostream& os, const pair<T,U>& A){
os << "(" << A.first <<", " << A.second << ")";
return os;
}
template<class T>
ostream& operator<<(ostream& os, const set<T>& S){
os << "set{";
for (auto a:S){
os << a;
auto it = S.find(a);
it++;
if (it!=S.end()){
os << ", ";
}
}
os << "}";
return os;
}
template<class T>
ostream& operator<<(ostream& os, const vec<T>& A){
os << "[";
rep(i,A.size()){
os << A[i];
if (i!=A.size()-1){
os << ", ";
}
}
os << "]" ;
return os;
}
pair<int,int> query(int d){
cout << "> " << d+1 << endl;
int nxt_v,nxt_d;
cin >> nxt_v >> nxt_d;
return {nxt_v-1,nxt_d};
}
void answer(int N,vec<vec<int>> edges){
vec<int> ans;
rep(v,edges.size()){
for (auto nv:edges[v]){
assert (nv!=-1);
if (v < nv){
ans.push_back(v);
ans.push_back(nv);
}
}
}
//cout << Q << " " << 2*N + 2*ans.size() << endl;
cout << "! ";
rep(i,ans.size()){
cout << ans[i]+1;
if (i == int(ans.size())-1){
cout << endl;
}
else{
cout << " ";
}
}
string judge;
cin>>judge;
assert (judge == "Correct");
}
void solve(){
int x,d;
cin>>x>>d;
x--;
int N = x+1;
vec<vec<int>> edge(N);
vec<int> deg(N,-1);
deg[x] = d;
edge[x].resize(d,-1);
vec<int> done(N,0);
map<pair<int,int>,int> e_to_idx;
vec<set<int>> need_back(N);
vec<int> parent(N,-1);
int pos = x;
while (true){
if (done[pos] == deg[pos]){
if (parent[pos] == -1) break;
assert (e_to_idx.count({pos,parent[pos]}));
query(e_to_idx[{pos,parent[pos]}]);
pos = parent[pos];
continue;
}
auto [nv,nv_d] = query(done[pos]);
edge[pos][done[pos]] = nv;
e_to_idx[{pos,nv}] = done[pos];
done[pos]++;
if (nv == parent[pos]){
assert (e_to_idx.count({nv,pos}));
query(e_to_idx[{nv,pos}]);
continue;
}
if (need_back[pos].count(nv)){
need_back[pos].erase(nv);
pos = nv;
continue;
}
if (N < nv+1){
N = nv + 1;
edge.resize(N);
deg.resize(N,-1);
done.resize(N,0);
parent.resize(N,-1);
need_back.resize(N);
}
if (deg[nv] == -1){
deg[nv] = nv_d;
edge[nv].resize(nv_d);
parent[nv] = pos;
pos = nv;
continue;
}
else{
need_back[nv].insert(pos);
pos = nv;
continue;
}
}
answer(N,edge);
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
cin>>T;
while (T--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
input:
2 1 1 2 1 1 1 2 1 1 1 Correct 1 3 2 2 1 3 2 2 4 2 1 3 3 1 1 3 3 1 1 3 4 2 2 2 4 2 2 2 1 3 Correct
output:
> 1 > 1 > 1 > 1 ! 1 2 > 1 > 1 > 1 > 2 > 1 > 2 > 1 > 2 > 1 > 3 > 2 > 2 > 2 > 1 ! 1 2 1 3 1 4 2 4
result:
ok correct! (2 test cases)
Test #2:
score: 0
Accepted
time: 177ms
memory: 3680kb
input:
1000 1 9 2 7 1 9 2 7 3 9 1 9 3 9 4 9 1 9 4 9 3 9 4 9 7 7 1 9 5 8 1 9 5 8 8 8 1 9 6 9 1 9 6 9 2 7 10 6 1 9 7 7 4 9 7 7 8 8 5 8 8 8 10 6 2 7 10 6 8 8 9 8 1 9 8 8 7 7 5 8 9 8 3 9 9 8 5 8 2 7 6 9 10 6 4 9 10 6 6 9 5 8 3 9 2 7 3 9 5 8 6 9 8 8 3 9 10 6 3 9 8 8 6 9 3 9 7 7 3 9 6 9 9 8 2 7 5 8 7 7 9 8 8 8 9...
output:
> 1 > 1 > 1 > 2 > 1 > 2 > 2 > 1 > 3 > 2 > 2 > 3 > 1 > 4 > 1 > 4 > 2 > 1 > 5 > 1 > 5 > 2 > 3 > 1 > 6 > 2 > 3 > 3 > 2 > 2 > 3 > 2 > 3 > 3 > 4 > 1 > 7 > 5 > 4 > 3 > 2 > 3 > 3 > 4 > 4 > 3 > 4 > 4 > 5 > 4 > 5 > 4 > 2 > 5 > 6 > 5 > 6 > 6 > 6 > 7 > 7 > 6 > 8 > 5 > 9 > 7 > 4 > 5 > 7 > 6 > 5 > 4 > 6 > 7 > 8 ...
result:
ok correct! (1000 test cases)
Test #3:
score: 0
Accepted
time: 128ms
memory: 3616kb
input:
500 1 19 2 8 1 19 2 8 17 10 1 19 3 7 1 19 3 7 20 6 1 19 4 8 1 19 4 8 3 7 11 8 1 19 5 7 1 19 5 7 7 11 1 19 6 7 1 19 6 7 5 7 6 7 17 10 2 8 17 10 6 7 11 8 3 7 11 8 8 4 1 19 7 11 5 7 7 11 16 7 1 19 8 4 11 8 8 4 15 8 1 19 9 7 1 19 9 7 4 8 12 7 1 19 10 9 1 19 10 9 5 7 10 9 17 10 14 9 1 19 11 8 16 7 13 4 1...
output:
> 1 > 1 > 1 > 2 > 1 > 2 > 1 > 2 > 2 > 1 > 3 > 1 > 3 > 2 > 3 > 1 > 4 > 1 > 4 > 2 > 1 > 5 > 1 > 5 > 2 > 3 > 3 > 2 > 2 > 3 > 4 > 2 > 3 > 3 > 1 > 6 > 2 > 2 > 3 > 1 > 7 > 2 > 3 > 3 > 1 > 8 > 1 > 8 > 2 > 3 > 1 > 9 > 1 > 9 > 2 > 4 > 3 > 4 > 1 > 10 > 4 > 2 > 1 > 11 > 2 > 3 > 3 > 3 > 5 > 4 > 4 > 5 > 6 > 5 > ...
result:
ok correct! (500 test cases)
Test #4:
score: 0
Accepted
time: 146ms
memory: 3800kb
input:
100 1 99 2 5 1 99 2 5 12 7 1 99 3 5 1 99 3 5 76 9 1 99 4 10 1 99 4 10 74 6 1 99 5 3 1 99 5 3 99 7 1 99 6 9 1 99 6 9 20 4 1 99 7 6 1 99 7 6 67 10 1 99 8 8 1 99 8 8 70 9 1 99 9 9 1 99 9 9 93 10 1 99 10 5 1 99 10 5 47 4 1 99 11 4 1 99 11 4 95 12 1 99 12 7 2 5 12 7 41 7 1 99 13 6 1 99 13 6 86 6 1 99 14 ...
output:
> 1 > 1 > 1 > 2 > 1 > 2 > 1 > 2 > 2 > 1 > 3 > 1 > 3 > 2 > 1 > 4 > 1 > 4 > 2 > 1 > 5 > 1 > 5 > 2 > 1 > 6 > 1 > 6 > 2 > 1 > 7 > 1 > 7 > 2 > 1 > 8 > 1 > 8 > 2 > 1 > 9 > 1 > 9 > 2 > 1 > 10 > 1 > 10 > 2 > 1 > 11 > 2 > 2 > 3 > 1 > 12 > 1 > 12 > 2 > 1 > 13 > 1 > 13 > 2 > 1 > 14 > 1 > 14 > 2 > 1 > 15 > 1 > ...
result:
ok correct! (100 test cases)
Test #5:
score: 0
Accepted
time: 122ms
memory: 4500kb
input:
10 1 999 2 8 1 999 2 8 717 8 1 999 3 9 1 999 3 9 311 9 1 999 4 8 1 999 4 8 876 8 1 999 5 7 1 999 5 7 866 6 1 999 6 7 1 999 6 7 687 9 1 999 7 4 1 999 7 4 587 8 1 999 8 4 1 999 8 4 98 7 1 999 9 13 1 999 9 13 935 11 1 999 10 11 1 999 10 11 232 7 1 999 11 7 1 999 11 7 84 8 1 999 12 7 1 999 12 7 595 7 1 ...
output:
> 1 > 1 > 1 > 2 > 1 > 2 > 1 > 2 > 2 > 1 > 3 > 1 > 3 > 2 > 1 > 4 > 1 > 4 > 2 > 1 > 5 > 1 > 5 > 2 > 1 > 6 > 1 > 6 > 2 > 1 > 7 > 1 > 7 > 2 > 1 > 8 > 1 > 8 > 2 > 1 > 9 > 1 > 9 > 2 > 1 > 10 > 1 > 10 > 2 > 1 > 11 > 1 > 11 > 2 > 1 > 12 > 1 > 12 > 2 > 1 > 13 > 1 > 13 > 2 > 1 > 14 > 1 > 14 > 2 > 1 > 15 > 1 >...
result:
ok correct! (10 test cases)
Test #6:
score: 0
Accepted
time: 166ms
memory: 5304kb
input:
4 1 999 2 24 1 999 2 24 293 19 1 999 3 20 1 999 3 20 804 22 1 999 4 17 1 999 4 17 992 26 1 999 5 29 1 999 5 29 134 20 1 999 6 21 1 999 6 21 883 18 1 999 7 21 1 999 7 21 10 14 1 999 8 19 1 999 8 19 214 18 1 999 9 21 1 999 9 21 420 29 1 999 10 14 816 16 1 999 11 12 1 999 11 12 814 13 1 999 12 17 1 999...
output:
> 1 > 1 > 1 > 2 > 1 > 2 > 1 > 2 > 2 > 1 > 3 > 1 > 3 > 2 > 1 > 4 > 1 > 4 > 2 > 1 > 5 > 1 > 5 > 2 > 1 > 6 > 1 > 6 > 2 > 1 > 7 > 1 > 7 > 2 > 1 > 8 > 1 > 8 > 2 > 1 > 9 > 2 > 1 > 10 > 1 > 10 > 2 > 1 > 11 > 1 > 11 > 2 > 1 > 12 > 1 > 12 > 2 > 1 > 13 > 1 > 13 > 2 > 1 > 14 > 1 > 14 > 2 > 1 > 15 > 1 > 15 > 2 ...
result:
ok correct! (4 test cases)
Test #7:
score: 0
Accepted
time: 133ms
memory: 5236kb
input:
4 1 199 2 106 1 199 2 106 114 107 1 199 3 95 1 199 3 95 74 101 1 199 4 102 1 199 4 102 56 101 1 199 5 103 1 199 5 103 117 106 1 199 6 103 1 199 6 103 4 102 44 100 1 199 7 110 1 199 7 110 178 97 1 199 8 109 1 199 8 109 2 106 8 109 20 108 1 199 9 104 1 199 9 104 85 92 1 199 10 98 1 199 10 98 128 99 1 ...
output:
> 1 > 1 > 1 > 2 > 1 > 2 > 1 > 2 > 2 > 1 > 3 > 1 > 3 > 2 > 1 > 4 > 1 > 4 > 2 > 1 > 5 > 1 > 5 > 2 > 3 > 1 > 6 > 1 > 6 > 2 > 1 > 7 > 1 > 7 > 2 > 3 > 3 > 1 > 8 > 1 > 8 > 2 > 1 > 9 > 1 > 9 > 2 > 1 > 10 > 1 > 10 > 2 > 1 > 11 > 1 > 11 > 2 > 1 > 12 > 1 > 12 > 2 > 1 > 13 > 1 > 13 > 2 > 1 > 14 > 1 > 14 > 2 > ...
result:
ok correct! (4 test cases)
Test #8:
score: 0
Accepted
time: 72ms
memory: 5188kb
input:
4 1 140 2 140 1 140 2 140 3 140 1 140 3 140 2 140 3 140 4 140 1 140 4 140 2 140 4 140 3 140 4 140 5 140 1 140 5 140 2 140 5 140 3 140 5 140 4 140 5 140 6 140 1 140 6 140 2 140 6 140 3 140 6 140 4 140 6 140 5 140 6 140 7 140 1 140 7 140 2 140 7 140 3 140 7 140 4 140 7 140 5 140 7 140 6 140 7 140 8 14...
output:
> 1 > 1 > 1 > 2 > 1 > 2 > 2 > 2 > 3 > 1 > 3 > 2 > 3 > 3 > 3 > 4 > 1 > 4 > 2 > 4 > 3 > 4 > 4 > 4 > 5 > 1 > 5 > 2 > 5 > 3 > 5 > 4 > 5 > 5 > 5 > 6 > 1 > 6 > 2 > 6 > 3 > 6 > 4 > 6 > 5 > 6 > 6 > 6 > 7 > 1 > 7 > 2 > 7 > 3 > 7 > 4 > 7 > 5 > 7 > 6 > 7 > 7 > 7 > 8 > 1 > 8 > 2 > 8 > 3 > 8 > 4 > 8 > 5 > 8 > 6 ...
result:
ok correct! (4 test cases)
Test #9:
score: 0
Accepted
time: 63ms
memory: 5092kb
input:
4 1 2498 2 2 1 2498 2 2 2500 2498 2 2 2500 2498 3 2 1 2498 3 2 2500 2498 3 2 2500 2498 4 2 1 2498 4 2 2500 2498 4 2 2500 2498 5 2 1 2498 5 2 2500 2498 5 2 2500 2498 6 2 1 2498 6 2 2500 2498 6 2 2500 2498 7 2 1 2498 7 2 2500 2498 7 2 2500 2498 8 2 1 2498 8 2 2500 2498 8 2 2500 2498 9 2 1 2498 9 2 250...
output:
> 1 > 1 > 1 > 2 > 1 > 2 > 2 > 1 > 2 > 2 > 2 > 2 > 3 > 1 > 3 > 2 > 3 > 2 > 4 > 1 > 4 > 2 > 4 > 2 > 5 > 1 > 5 > 2 > 5 > 2 > 6 > 1 > 6 > 2 > 6 > 2 > 7 > 1 > 7 > 2 > 7 > 2 > 8 > 1 > 8 > 2 > 8 > 2 > 9 > 1 > 9 > 2 > 9 > 2 > 10 > 1 > 10 > 2 > 10 > 2 > 11 > 1 > 11 > 2 > 11 > 2 > 12 > 1 > 12 > 2 > 12 > 2 > 1...
result:
ok correct! (4 test cases)
Extra Test:
score: 0
Extra Test Passed