QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404071#4889. 愚蠢的在线法官Butanlishi0 325ms137464kbC++142.3kb2024-05-03 10:59:512024-05-03 10:59:53

Judging History

你现在查看的是最新测评结果

  • [2024-05-03 10:59:53]
  • 评测
  • 测评结果:0
  • 用时:325ms
  • 内存:137464kb
  • [2024-05-03 10:59:51]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define rg int
#define ci const int
#define ls x<<1
#define rs x<<1|1
#define mid ((l+r)>>1)
#define ld long double
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fd(i,l,r) for(int i=(l);i>=(r);--i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
#define gcd __gcd
#define P(x) __builtin_popcountll(x)
using namespace std;
ci N=1e6+5,M=5e3+5,mod=998244353,_g=3,_ig=(mod+1)/3;
ll ksm(ll a,ll b=mod-2)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%mod;
		a=(ll)a*a%mod,b>>=1;
	}
	return ans;
}
const ld eps=1e-10;
inline ll read(){ll u,f=1;char o;while((o=getchar())<48||o>57)if(o==45)f=-1;u=(o^48);while((o=getchar())>=48&&o<=57)u=(u<<1)+(u<<3)+(o^48);return u*f;}
void write(ll x){if(x<0)putchar(45),x=-x;if(x>9)write(x/10);putchar(x%10+48);}
mt19937 rad(chrono::steady_clock::now().time_since_epoch().count());
ll n,k,a[N],v[N],to[M][M],lca[N][20],ceng[N];
vector<ll>w[N];
bool f[N];
void tree(int x,int c)
{
	f[x]=1;
	ceng[x]=c;
//	cout<<x<<' '<<c<<'\n';
	for(auto d:w[x])if(!f[d])
	{
		lca[d][0]=x;
		int s=0;
		while(lca[lca[d][s]][s])
		{
			lca[d][s+1]=lca[lca[d][s]][s];
			++s; 
		}
		tree(d,c+1); 
	}
}
int find(int x,int y)
{//cout<<x<<' '<<y<<'\n';
	if(ceng[x]<ceng[y])swap(x,y);
	fd(i,19,0)if(ceng[x]-(1<<i)>=ceng[y])x=lca[x][i];
	fd(i,19,0)if(lca[x][i]!=lca[y][i])x=lca[x][i],y=lca[y][i];
	if(x!=y)x=lca[x][0];
//	cout<<x<<'\n';
	return x;
}
ll guess()
{
	ll f=1,ans=1;
	for(rg i=1;i<=k;++i)
	{
		if(to[i][i]==0)
		{
			for(rg j=i+1;j<=k;++j)if(to[j][i]!=0)
			{
				f=-f;
				swap(to[i],to[j]);
			}
		}
		ll inv=ksm(to[i][i],mod-2);
		for(rg j=i+1;j<=k;++j)
		{
			ll u=to[j][i]*inv%mod;
			for(rg o=i;o<=k;++o)to[j][o]=(to[j][o]-u*to[i][o])%mod;
		}
		ans=ans*to[i][i]%mod;
	}
	ans=ans*f;
	return (ans+mod)%mod;
}
int main()
{//freopen("1.in","r",stdin);
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int T=1;
	while(T--)
	{
		n=read();k=read();
		fo(i,1,n)v[i]=read();
		fo(i,1,k)a[i]=read();
		fu(i,1,n)
		{
			ll x=read(),y=read();
			w[x].push_back(y);
			w[y].push_back(x);
		}
		tree(1,1);
		fo(i,1,k)fo(j,1,k)to[i][j]=v[find(a[i],a[j])];
		fo(i,1,k)
		{
			fo(j,1,k)cout<<to[i][j]<<' ';
			cout<<'\n';
		}
		cout<<guess()<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

499999 500000
879485015 176694934 629415436 677018935 33186863 696674214 19586946 878479076 318116264 823399347 140314195 715329843 996129441 446979068 600062488 847953138 978347569 865596472 147980317 199880680 187953368 989585254 457868128 466175307 381871948 369138343 826894839 963935318 36550896...

output:


result:


Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 27084kb

input:

10 1
663730929 273617752 74933376 562874267 346105266 779139305 198742356 291012786 227170675 127136999
2
10 8
5 10
1 5
9 8
6 10
4 6
3 1
2 4
7 3

output:

273617752 
273617752

result:

wrong answer Output contains longer sequence [length = 2], but answer contains 1 elements

Subtask #3:

score: 0
Wrong Answer

Test #43:

score: 0
Wrong Answer
time: 325ms
memory: 137464kb

input:

500000 600
375999961 486674339 753591626 263678997 153496902 843204506 294273913 59353025 80121537 938426018 309354784 359915003 480316315 880954496 544396164 478808641 583197144 202111021 277512785 193266475 511298159 750302398 30978705 278891583 701736665 516664158 47658598 456194527 517690925 870...

output:

606346214 661622892 171907730 437246895 265452657 265452657 661622892 171907730 437246895 437246895 437246895 171907730 265452657 265452657 171907730 248735605 92358985 171907730 171907730 661622892 437246895 661622892 92358985 171907730 171907730 437246895 92358985 437246895 92358985 171907730 2654...

result:

wrong answer 1st numbers differ - expected: '739558267', found: '606346214'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Time Limit Exceeded

Test #77:

score: 0
Time Limit Exceeded

input:

500000 500000
200910665 704700912 664276 824905098 512233060 623259142 478040808 509760810 756074623 387351466 261683363 140331101 135736712 184881987 425557684 61914673 951508934 787260914 386285199 40458274 175322609 429002885 606957721 742057849 342942076 104844271 656874266 826513447 76400873 55...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #1:

0%