QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196535 | #6964. Werewolves | yiyiyi | WA | 23ms | 239416kb | C++14 | 1.8kb | 2023-10-01 18:46:35 | 2023-10-01 18:46:35 |
Judging History
answer
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<bitset>
#include<set>
#define int long long
#define lowbit(x) x&(-x)
#define mp make_pair
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define forE(i,x) for(int i=head[x];i;i=nxt[i])
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int maxn=1e7+5;
const int maxm=1e7+5;
const int mod=998244353;
const int INF=1e18;
inline int read()
{
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=x*10+(c-'0');
c=getchar();
}
return x*f;
}
int n,m;
int nowid=0,mid;
int pre[maxn];
inline int quickpow(int x,int tim)
{
if(tim<0) return 0;
int res=1;
while(tim)
{
if(tim&1) res=res*x;
x=x*x;
tim>>=1;
}
return res;
}
int mid1,mid2;
vector<int> ans[maxn];
inline void dfs(int x,int mx)
{
if(x==n)
{
++nowid;
if(nowid<=mid1)
{
int dif=(mid1-nowid)%n;
rep(i,1,n) ans[i].push_back(pre[(i+dif)<=n?(i+dif):((i+dif-n))]);
}
else
{
int dif=(nowid-mid2)%n;
rep(i,1,n) ans[i].push_back(pre[(i-dif)>0?(i-dif):(i-dif+n)]);
}
return;
}
rep(i,1,m)
{
if(i<mx) continue;
dfs(x+1,max(mx,i));
}
nowid+=quickpow(m,n-x-2)*(n-m);
}
int C(int m,int n){
int res=1;
for (int i=1;i<=n;++i)res=res*(m-i+1)/i;
return res;
}
signed main()
{
int T=read();
while(T--)
{
nowid=0;
n=read(),m=read();
int now=1;
rep(i,1,n) pre[i]=now,now=(now==m)?1:now+1;
rep(i,1,n) ans[i].clear();
int r=C(n+n-2,n-1);
mid1=mid2=(r+1)/2;
dfs(1,0);
rep(i,1,n)
{
for(auto j:ans[i]) printf("%lld ",j);
puts("");
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 23ms
memory: 239416kb
input:
45 5 3 7 3 14 2 8 3 9 4 6 3 4 4 7 2 11 2 12 2 7 5 9 5 9 2 5 2 19 2 16 2 6 2 6 4 2 2 12 3 5 5 10 2 8 6 18 2 7 6 13 3 10 3 8 5 17 2 10 4 8 2 11 3 15 2 8 4 4 2 6 6 9 3 20 2 13 2 5 4 7 7 7 4 3 3 21 2 6 5
output:
2 1 3 2 1 2 2 1 2 2 3 2 1 3 1 1 2 1 3 2 1 3 2 1 3 1 3 2 1 2 2 1 2 1 3 2 1 3 2 1 2 1 3 2 1 3 2 1 2 1 3 2 1 3 2 1 2 1 1 2 1 3 2 1 2 1 1 2 1 1 2 1 2 2 3 1 3 2 1 3 2 1 3 2 1 1 1 3 1 2 1 1 3 1 2 1 1 1 3 1 2 1 1 1 1 3 2 1 3 2 1 3 2 2 1 1 2 3 2 1 1 2 3 2 2 1 1 2 3 2 2 2 1 1 3 2 1 3 2 1 3 3 2 1 3 1 3...
result:
wrong answer Strategy not correct