QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420240#7012. Rikka with An Unnamed TempleLynkcatWA 1716ms14104kbC++203.8kb2024-05-24 15:44:312024-05-24 15:44:38

Judging History

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

  • [2024-05-24 15:44:38]
  • 评测
  • 测评结果:WA
  • 用时:1716ms
  • 内存:14104kb
  • [2024-05-24 15:44:31]
  • 提交

answer

#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 1000000007
#define sz(x) ((int)((x).size()))
#define int ll
// #define N 
using namespace std;
const int N=200005;

pa pre[100005][105],suf[100005][105];
pa tr[N<<2];
int n,m;
int w[N],c[N];
poly G[N],rG[N];
int p[N],ip[N];
int cnt;
int K,T;
pa E[N];
int ru[N];

void trans(pa &x,pa &y,int w)
{
	if (x.se==0) return;
	if (x.fi+w==y.fi) y.se=(y.se+x.se)%mod;
	else if (x.fi+w>y.fi) y.fi=x.fi+w,y.se=x.se;
}
void build(int k,int l,int r)
{
	tr[k]=mp(-inf,0);
	if (l==r) return;
	int mid=l+(r-l)/2;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
}
void update(int k,int l,int r,int L,int R,pa x)
{
	if (L<=l&&r<=R)
	{
		trans(x,tr[k],0);
		return;
	}
	int mid=l+(r-l)/2;
	if (L<=mid) update(k<<1,l,mid,L,R,x);
	if (R>mid) update(k<<1|1,mid+1,r,L,R,x);
}
pa query(int k,int l,int r,int L)
{
	// if (p[L]==2) cerr<<"!!!!"<<tr[k].fi<<" "<<tr[k].se<<endl;
	if (l==r) return tr[k];
	int mid=l+(r-l)/2;
	pa res=tr[k];
	if (L<=mid) 
	{
		pa x=query(k<<1,l,mid,L);
		trans(x,res,0);
	} else
	{
		pa x=query(k<<1|1,mid+1,r,L);
		trans(x,res,0);
	}
	return res;
}
void BellaKira()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++)
		cin>>w[i]>>c[i];
	for (int i=1;i<=m;i++)
	{
		cin>>E[i].fi>>E[i].se;
		G[E[i].fi].push_back(E[i].se);
		rG[E[i].se].push_back(E[i].fi);
	}
	cin>>K>>T;

	queue<int>q;

	for (int i=1;i<=n;i++) 
		for (int j=0;j<K;j++)
			pre[i][j]=suf[i][j]=mp(-inf,0);

	for (int i=1;i<=n;i++) ru[i]=0;
	for (int i=1;i<=m;i++) 
		ru[E[i].se]++;
	for (int i=1;i<=n;i++) 
		if (!ru[i]) q.push(i);
	pre[1][w[1]%K]=mp(c[1],1);
	// cerr<<ru[n]<<endl;
	while (!q.empty())
	{
		int u=q.front();q.pop();
		p[++cnt]=u;ip[u]=cnt;
		// for (int j=K-1;j>=0;j--)
		// {
		// 	if (pre[u][j].se)
		// 	{
		// 		cerr<<u<<","<<j<<": "<<pre[u][j].fi<<" "<<K<<" "<<T<<" "<<ru[300]<<endl;
		// 		break;
		// 	}
		// }
		for (auto v:G[u])
		{
			ru[v]--;
			for (int j=0;j<K;j++)
				trans(pre[u][j],pre[v][(j+w[v])%K],c[v]);
			if (!ru[v]) q.push(v);
		}
	}
	// cerr<<pre[n][T].se<<"???"<<endl;
	for (int i=1;i<=n;i++) ru[i]=0;
	for (int i=1;i<=m;i++) 
		ru[E[i].fi]++;
	for (int i=1;i<=n;i++) 
		if (!ru[i]) q.push(i);
	suf[n][w[n]%K]=mp(c[n],1);
	while (!q.empty())
	{
		int u=q.front();q.pop();
		for (auto v:rG[u])
		{
			ru[v]--;
			for (int j=0;j<K;j++)
				trans(suf[u][j],suf[v][(j+w[v])%K],c[v]);
			if (!ru[v]) q.push(v);
		}
	}
	// cerr<<suf[1][T].se<<"???"<<endl;
	build(1,1,n);
	for (int i=1;i<=m;i++)
	{
		auto [x,y]=E[i];
		int l=ip[x],r=ip[y];
		pa now=mp(-inf,0);
		for (int j=0;j<K;j++)
		{
			if (pre[x][j].se==0||suf[y][(T-j+K)%K].se==0) continue;
			pa tmp;
			tmp.fi=pre[x][j].fi+suf[y][(T-j+K)%K].fi;
			tmp.se=pre[x][j].se*suf[y][(T-j+K)%K].se%mod;
			if (now.fi==tmp.fi) now.se=(now.se+tmp.se)%mod;
			else 
			if (now.fi<tmp.fi) now.fi=tmp.fi,now.se=tmp.se;
		}
		// if (x==2&&now.se)
			// cerr<<i<<" "<<now.fi<<" "<<now.se<<" "<<l<<" "<<r<<" "<<ip[2]<<endl;
		if (l+1<=r-1) update(1,1,n,l+1,r-1,now);
	}
	for (int i=1;i<=n;i++)
	{
		int mn=-inf;
		for (int j=0;j<K;j++) mn=max(mn,pre[i][j].fi+suf[i][(T+K-j+w[i]%K)%K].fi-c[i]);
		if (mn!=pre[n][T].fi)
		{
			cout<<pre[n][T].fi<<" "<<pre[n][T].se<<'\n';
			continue;
		}
		pa now=query(1,1,n,ip[i]);
		if (now.se==0) cout<<"-1\n";
		else cout<<now.fi<<" "<<now.se<<'\n';
	}

	cnt=0;
	for (int i=1;i<=n;i++) poly().swap(G[i]),poly().swap(rG[i]),ru[i]=0;
}
signed main()
{
	// freopen("1.out","w",stdout);
	IOS;
	cin.tie(0);
	int T=1;
	cin>>T;
	while (T--)
	{
		BellaKira();
	}
}
/*list:
1.mod 998244353 or 1e9+7 or ???
2.N
3.duipai shuju xingtai duoyidian
...
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 14104kb

input:

1
4 5
1 2
2 3
3 4
4 2
1 2
1 3
2 4
3 4
1 4
5 3

output:

-1
8 1
-1
-1

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 1716ms
memory: 13932kb

input:

840
300 2000
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1...

output:

-1
26 4598303
26 5863883
26 5015595
26 5885768
26 5825352
26 5282239
26 5677503
26 5663242
26 5549866
26 5865190
26 5748616
26 5885768
26 5833529
26 5635401
26 5885768
26 4779744
26 2604267
26 5001275
26 5885768
26 5820512
26 4314551
26 5885768
26 4334970
26 5885768
26 5712718
26 3266408
26 5807851
...

result:

wrong answer 11101st lines differ - expected: '-1', found: '-1000000000000000000 0'