QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#772282 | #9251. Graph Changing | 401rk8 | WA | 0ms | 3908kb | C++17 | 3.1kb | 2024-11-22 18:16:07 | 2024-11-22 18:16:08 |
Judging History
answer
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx;
#define For(i,x,y,...) for(int i=x,##__VA_ARGS__;i<=(y);++i)
#define rFor(i,x,y,...) for(int i=x,##__VA_ARGS__;i>=(y);--i)
#define Rep(i,x,y,...) for(int i=x,##__VA_ARGS__;i<(y);++i)
#define pb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mkp make_pair
#define mem(a,x,n) memset(a,x,sizeof(a[0])*(n+2))
typedef long long LL; typedef vector<int> Vi; typedef pair<int,int> Pii;
auto ckmax=[](auto &x,auto y) { return x<y ? x=y,true : false; };
auto ckmin=[](auto &x,auto y) { return y<x ? x=y,true : false; };
sfmt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r) { return uniform_int_distribution<>(l,r)(mt); }
template<typename T=int>T read() { T x; cin>>x; return x; }
const int mod = 998244353;
struct mint {
int x; mint(int x=0):x(x<0?x+mod:x<mod?x:x-mod){}
mint(LL y) { y%=mod, x=y<0?y+mod:y; }
mint& operator += (const mint &y) { x=x+y.x<mod?x+y.x:x+y.x-mod; return *this; }
mint& operator -= (const mint &y) { x=x<y.x?x-y.x+mod:x-y.x; return *this; }
mint& operator *= (const mint &y) { x=1ll*x*y.x%mod; return *this; }
friend mint operator + (mint x,const mint &y) { return x+=y; }
friend mint operator - (mint x,const mint &y) { return x-=y; }
friend mint operator * (mint x,const mint &y) { return x*=y; }
}; mint Pow(mint x,LL y=mod-2) { mint z(1);for(;y;y>>=1,x*=x)if(y&1)z*=x;return z; }
int t,n,k,x,y;
map<int,int> f[8][8][8];
int MAIN() {
cin>>t>>n>>k>>x>>y;
if( x > y ) swap(x,y);
if( !t ) return y-x;
if( k >= n ) return -1;
if( k == 1 ) return 1;
else if( k == 2 ) {
if( n == 3 ) return t==1 ? (y-x==2?1:-1) : -1;
else if( n >= 4 ) {
if( t&1 ) {
if( y-x >= k ) return 1;
if( x-1 >= k || n-y >= k ) return 2;
if( y-1 >= k && n-x >= k ) return 3;
} else if( ~t&1 ) return y-x;
}
} else if( k == 3 ) {
if( n <= 7 ) return f[n][x][y].count(t) ? f[n][x][y][t] : -1;
else if( n >= 8 ) {
if( t == 1 ) {
if( y-x >= k ) return 1;
if( x-1 >= k || n-y >= k ) return 2;
return -1;
} else if( t > 1 ) return -1;
}
} else if( k > 3 ) {
if( t == 1 ) {
if( y-x >= k ) return 1;
if( x-1 >= k || n-y >= k ) return 2;
if( y-1 >= k && n-x >= k ) return 3;
return -1;
} else if( t > 1 ) return -1;
}
assert(0);
} signed main() {
#ifdef FS
freopen("in","r",stdin); freopen("out","w",stdout);
#endif
ios::sync_with_stdio(0);cin.tie(0);
k = 3;
for(n = 4; n <= 7; ++n) {
Vi e[8];
Rep(i,1,n) e[i].pb(i+1), e[i+1].pb(i);
for(t = 0; ; ++t) {
For(i,1,n) {
queue<int> q;
f[n][i][i][t] = 0, q.emplace(i);
while( sz(q) ) {
int u = q.front(); q.pop();
for(int v : e[u]) if( !f[n][i][v].count(t) )
f[n][i][v][t] = f[n][i][u][t]+1, q.emplace(v);
}
}
bool flg = 0;
Vi ee[8];
For(u,1,n) For(v,1,n) if( f[n][u][v][t] >= k ) flg = 1, ee[u].pb(v);
if( !flg ) break;
swap(e,ee);
}
}
int lft=read(); while( lft-- ) {
cout<<MAIN()<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
5 1 5 3 2 4 1 10 4 2 4 2 10 5 2 4 1 3 2 1 3 1 3 2 1 2
output:
3 2 -1 1 -1
result:
ok 5 lines
Test #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