QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#330241 | #8056. Travel 2 | ucup-team180# | AC ✓ | 225ms | 9536kb | C++23 | 7.9kb | 2024-02-17 13:56:45 | 2024-02-17 13:56:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
using ull = unsigned long long;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
template<class T> using pqmin = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pqmax = priority_queue<T>;
const ll inf=LLONG_MAX/3;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define si(x) ll(x.size())
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rng(i,l,r) for(ll i=l;i<r;i++)
#define gnr(i,l,r) for(ll i=r-1;i>=l;i--)
#define fore(i, a) for(auto &&i : a)
#define fore2(a, b, v) for(auto &&[a, b] : v)
#define fore3(a, b, c, v) for(auto &&[a, b, c] : v)
template<class T> bool chmin(T& a, const T& b){ if(a <= b) return 0; a = b; return 1; }
template<class T> bool chmax(T& a, const T& b){ if(a >= b) return 0; a = b; return 1; }
template<class T, class U> bool chmin(T& a, const U& b){ return chmin(a, (T)b); }
template<class T, class U> bool chmax(T& a, const U& b){ return chmax(a, (T)b); }
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define VLL(name,size) vector<ll>name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>> name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>> name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>> name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define SUM(...) accumulate(all(__VA_ARGS__),0LL)
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }
template<class T, class F = less<>> void sor(T& a, F b = F{}){ sort(all(a), b); }
template<class T> void uniq(T& a){ sor(a); a.erase(unique(all(a)), end(a)); }
void outb(bool x){cout<<(x?"Yes":"No")<<"\n";}
ll max(int x, ll y) { return max((ll)x, y); }
ll max(ll x, int y) { return max(x, (ll)y); }
int min(int x, ll y) { return min((ll)x, y); }
int min(ll x, int y) { return min(x, (ll)y); }
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
ll gcd(ll a,ll b){return (b?gcd(b,a%b):a);}
vector<pll> factor(ull x){ vector<pll> ans; for(ull i = 2; i * i <= x; i++) if(x % i == 0){ ans.push_back({i, 1}); while((x /= i) % i == 0) ans.back().second++; } if(x != 1) ans.push_back({x, 1}); return ans; }
vector<ll> divisor(ull x){ vector<ll> ans; for(ull i = 1; i * i <= x; i++) if(x % i == 0) ans.push_back(i); per(i,ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]); return ans; }
vll prime_table(ll n){vec(ll,isp,n+1,1);vll res;rng(i,2,n+1)if(isp[i]){res.pb(i);for(ll j=i*i;j<=n;j+=i)isp[j]=0;}return res;}
ll powmod(lll x,ll y,lll mod){lll res=1; while(y){ if(y&1)res=res*x%mod; x=x*x%mod; y>>=1;} return res; }
ll modinv(ll a,ll m){ll b=m,u=1,v=0;while(b){ll t=a/b;a-=t*b;swap(a,b);u-=t*v;swap(u,v);}u%=m;if(u<0)u+=m;return u;}
template <class T, class S> pair<T, S> operator-(const pair<T, S> &x) { return pair<T, S>(-x.first, -x.second); }
template <class T, class S> pair<T, S> operator-(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi - y.fi, x.se - y.se); }
template <class T, class S> pair<T, S> operator+(const pair<T, S> &x, const pair<T, S> &y) { return pair<T, S>(x.fi + y.fi, x.se + y.se); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.fi, r.fi), min(l.se, r.se)); }
template <class T, class S> pair<T, S> operator+=(pair<T, S> &l, const pair<T, S> &r) { return l = l + r; }
template <class T, class S> pair<T, S> operator-=(pair<T, S> &l, const pair<T, S> &r) { return l = l - r; }
template <class T> bool intersect(const pair<T, T> &l, const pair<T, T> &r) { return (l.se < r.se ? r.fi < l.se : l.fi < r.se); }
template <class T> vector<T> &operator++(vector<T> &v) {
fore(e, v) e++;
return v;
}
template <class T> vector<T> operator++(vector<T> &v, int) {
auto res = v;
fore(e, v) e++;
return res;
}
template <class T> vector<T> &operator--(vector<T> &v) {
fore(e, v) e--;
return v;
}
template <class T> vector<T> operator--(vector<T> &v, int) {
auto res = v;
fore(e, v) e--;
return res;
}
template <class T> vector<T> &operator+=(vector<T> &l, const vector<T> &r) {
fore(e, r) l.eb(e);
return l;
}
template<class... Ts> void in(Ts&... t);
[[maybe_unused]] void print(){}
template<class T, class... Ts> void print(const T& t, const Ts&... ts);
template<class... Ts> void out(const Ts&... ts){ print(ts...); cout << '\n'; }
namespace IO{
#define VOID(a) decltype(void(a))
struct S{ S(){ cin.tie(nullptr)->sync_with_stdio(0); fixed(cout).precision(12); } }S;
template<int I> struct P : P<I-1>{};
template<> struct P<0>{};
template<class T> void i(T& t){ i(t, P<3>{}); }
void i(vector<bool>::reference t, P<3>){ int a; i(a); t = a; }
template<class T> auto i(T& t, P<2>) -> VOID(cin >> t){ cin >> t; }
template<class T> auto i(T& t, P<1>) -> VOID(begin(t)){ for(auto&& x : t) i(x); }
template<class T, size_t... idx> void ituple(T& t, index_sequence<idx...>){ in(get<idx>(t)...); }
template<class T> auto i(T& t, P<0>) -> VOID(tuple_size<T>{}){ ituple(t, make_index_sequence<tuple_size<T>::value>{}); }
template<class T> void o(const T& t){ o(t, P<4>{}); }
template<size_t N> void o(const char (&t)[N], P<4>){ cout << t; }
template<class T, size_t N> void o(const T (&t)[N], P<3>){ o(t[0]); for(size_t i = 1; i < N; i++){ o(' '); o(t[i]); } }
template<class T> auto o(const T& t, P<2>) -> VOID(cout << t){ cout << t; }
template<class T> auto o(const T& t, P<1>) -> VOID(begin(t)){ bool first = 1; for(auto&& x : t) { if(first) first = 0; else o(' '); o(x); } }
template<class T, size_t... idx> void otuple(const T& t, index_sequence<idx...>){ print(get<idx>(t)...); }
template<class T> auto o(T& t, P<0>) -> VOID(tuple_size<T>{}){ otuple(t, make_index_sequence<tuple_size<T>::value>{}); }
#undef VOID
}
#define unpack(a) (void)initializer_list<int>{(a, 0)...}
template<class... Ts> void in(Ts&... t){ unpack(IO::i(t)); }
template<class T, class... Ts> void print(const T& t, const Ts&... ts){ IO::o(t); unpack(IO::o((cout << ' ', ts))); }
#undef unpack
void push(ll i){
cout<<"> "<<i+1<<endl;
}
void solve(){
const ll N=2510;
vec(ll,p,N,-1);
vec(set<ll>,baby,N);
// vec((map<ll,ll>),ids,N);
vector<map<ll,ll> >ids(N);
set<pll> ans;
auto add_edge=[&](ll x,ll y){
if(x==-1||y==-1)return;
if(x>y)swap(x,y);
ans.insert({x,y});
};
vec(ll,pret,N,0);
ll cnt=0;
function<void(ll,ll)> func=[&](ll from,ll index){
cnt++;
LL(x,d);
if(-2!=from){
add_edge(from,x);
ids[from][x]=index;
}
if(!~p[x]){
p[x]=from;
if(-2!=from)baby[from].insert(x);
}
if(baby[x].count(from)){
// cout<<"baby "<<endl;
baby[x].erase(from);
push(ids[x][from]);
func(x,ids[x][from]);
return;
}
if(si(ids[x])<d){
// cout<<"seek "<<si(ids[x])<<endl;
ll i=si(ids[x]);
push(i);
func(x,i);
return;
}
if(!pret[x]&&p[x]>=0){
// cout<<"pret "<<endl;
pret[x]=1;
push(ids[x][p[x]]);
func(x,ids[x][p[x]]);
return;
}
return;
};
func(-2,0);
// out("cnt=",cnt);
// out("p=",p);
cout<<"!";
fore2(x,y,ans){
cout<<" "<<x<<" "<<y;
}
cout<<endl;
STR(correct);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
ll t;
cin>>t;
while(t--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3888kb
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
Test #2:
score: 0
Accepted
time: 225ms
memory: 3904kb
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
Test #3:
score: 0
Accepted
time: 170ms
memory: 4084kb
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
Test #4:
score: 0
Accepted
time: 189ms
memory: 4284kb
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
Test #5:
score: 0
Accepted
time: 139ms
memory: 6588kb
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
Test #6:
score: 0
Accepted
time: 175ms
memory: 9536kb
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
Test #7:
score: 0
Accepted
time: 184ms
memory: 9408kb
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
Test #8:
score: 0
Accepted
time: 85ms
memory: 8920kb
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
Test #9:
score: 0
Accepted
time: 105ms
memory: 7060kb
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
Extra Test:
score: 0
Extra Test Passed