QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#176755#6331. Jewel Gameucup-team1209TL 11ms9232kbC++145.0kb2023-09-11 23:13:012023-09-11 23:13:01

Judging History

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

  • [2023-09-11 23:13:01]
  • 评测
  • 测评结果:TL
  • 用时:11ms
  • 内存:9232kb
  • [2023-09-11 23:13:01]
  • 提交

answer

#include<bits/stdc++.h>
namespace my_std{
    using namespace std;
    #define pii pair<int,int>
    #define fir first
    #define sec second
    #define MP make_pair
    #define rep(i,x,y) for (int i=(x);i<=(y);i++)
    #define drep(i,x,y) for (int i=(x);i>=(y);i--)
    #define go(x) for (int i=head[x];i;i=edge[i].nxt)
    #define templ template<typename T>
	#define sz 33
    typedef long long ll;
    typedef double db;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
    templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
    templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
    templ inline void read(T& t) {
        t=0;char f=0,ch=getchar();double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t=(f?-t:t);
    }
    template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
    void file() {
        #ifdef zqj
        freopen("a.in","r",stdin);
        #endif
    }
    inline void chktime() {
        #ifdef zqj
        cerr<<clock()/1000.0<<'\n';
        #endif
    }
    #ifdef mod
    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
    ll inv(ll x){return ksm(x,mod-2);}
    #else
    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
    #endif
}
using namespace my_std;

int N;
ll f[2*sz*sz]; int type[2*sz*sz];
unordered_set<int>V[2*sz*sz],V1[2*sz*sz];

priority_queue<pair<ll,int>>S;

int del[2*sz*sz];
void delete_vertex(int x);
void delete_edge(int x,int v) {
	assert(V[x].count(v)&&V1[v].count(x));
	V[x].erase(v),V1[v].erase(x);
	if (chkmax(f[x],-f[v])) S.push({f[x],x});
	if (!V[x].size()&&!del[x]) delete_vertex(x);
}
void delete_vertex(int x) {
	del[x]=1;
	while (V[x].size()) delete_edge(x,*(V[x].begin()));
	while (V1[x].size()) delete_edge(*(V1[x].begin()),x);
};

void solve() {
	// queue<pii>q;
	// set<pair<ll,int>>S;
	// rep(i,0,N-1) {
	// 	for (auto v:V[i]) {
	// 		if (-f[v]<=f[i]) q.push({i,v});
	// 		del[i][v]=0;
	// 	}
	// 	S.insert({f[i],i});
	// }
	// while (q.size()||S.size()) {
	// 	while (q.size()) {
	// 		auto [x,v]=q.front(); q.pop();
	// 		V[x].erase(v),V1[v].erase(x);
	// 		if (-f[v]>f[x]) {
	// 			S.erase({x,f[x]}),f[x]=-f[v],S.insert({x,f[x]});
	// 			for (auto xx:V1[x]) if (-f[x]<=f[xx]) q.push({xx,x});
	// 		}
	// 		if (!V[x].size()) {
	// 			for (auto xx:V1[x]) q.push({xx,x});
	// 			S.erase({x,f[x]});
	// 		}
	// 	}
	// }

	// queue<int>q;
	// set<pair<ll,int>>S;
	// rep(i,0,N-1) {
	// 	unordered_set<int>vv;
	// 	for (auto v:V[i])
	// 		if (-f[v]<=f[i]) V1[v].erase(i);
	// 		else vv.insert(v);
	// 	V[i]=vv;
	// 	if (!vv.size()) q.push(i);
	// 	S.insert({f[i],i});
	// 	del[i]=0;
	// }
	// while (q.size()||S.size()) {
	// 	while (q.size()) {
	// 		int x=q.front(); q.pop();
	// 		del[x]=1;
	// 		S.erase({f[x],x});
	// 		for (auto v:V1[x]) if (!del[v]) {
	// 			if (-f[x]>f[v]) S.erase({f[v],v}),f[v]=-f[x],S.insert({f[v],v});
	// 			for (auto vv:V1[v]) if (!del[vv]&&-f[v]<=f[vv]) {
	// 				V[vv].erase(v);
	// 				if (!V[vv].size()) q.push(vv);
	// 			}
	// 			assert(V[v].count(x));
	// 			V[v].erase(x);
	// 			if (!V[v].size()) q.push(v);
	// 		}
	// 	}
	// 	if (S.size()) {
	// 		auto [w,x]=*(S.rbegin());
	// 		del[x]=1;
	// 		if (w<0) {
	// 			for (auto [w,x]:S) f[x]=0;
	// 			return;
	// 		}
	// 		for (auto v:V1[x]) if (!del[v]) {
	// 			assert(V[v].count(x));
	// 			V[v].erase(x);
	// 			if (!V[v].size()) q.push(v);
	// 		}
	// 	}
	// }

	rep(i,0,N-1) S.push({f[i],i}),del[i]=0;
	while (S.size()) {
		auto [w,x]=S.top(); S.pop();
		if (del[x]||f[x]!=w) continue;
		if (w<0) {
			rep(x,0,N-1) if (!del[x]) f[x]=0;
			return;
		}
		delete_vertex(x);
	}
}

int n,m,A,B,K;
int e[sz][sz];
int pos[sz],id[sz]; ll w[sz];
ll dp[1<<10][2][sz][sz];

int main() {
    file();
    read(n,m,A,B),--A,--B;
	int x,y;
	while (m--) read(x,y),e[x-1][y-1]=1;
	read(K);
	rep(i,0,n-1) id[i]=-1;
	rep(i,0,K-1) read(pos[i],w[i]),--pos[i],id[pos[i]]=i;
	rep(s,0,(1<<K)-1) {
		N=2*n*n;
		rep(t,0,1) rep(i,0,n-1) if (id[i]==-1||!(s>>id[i]&1)) rep(j,0,n-1) if (id[j]==-1||!(s>>id[j]&1)) {
			int x=t*n*n+i*n+j;
			f[x]=-1e18;
			rep(k,0,n-1) if (e[t?j:i][k]) {
				if (id[k]==-1||!(s>>id[k]&1)) {
					int y=(t?(i*n+k):(n*n+k*n+j));
					V[x].insert(y),V1[y].insert(x);
				}
				else {
					ll ww=w[id[k]];
					if (t) ww-=dp[1<<id[k]^s][0][i][k];
					else ww+=dp[1<<id[k]^s][1][k][j];
					chkmax(f[x],ww);
				}
			}
		}
		solve();
		rep(k,0,1) rep(i,0,n-1) if (id[i]==-1||!(s>>id[i]&1)) rep(j,0,n-1) if (id[j]==-1||!(s>>id[j]&1)) {
			int x=k*n*n+i*n+j;
			dp[s][k][i][j]=(k?-1:1)*f[x];
			V[x].clear(),V1[x].clear();
		}
	}
	cout<<dp[(1<<K)-1][0][A][B]<<'\n';
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4088kb

input:

5 16 1 1
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 2
3 4
3 5
4 2
4 3
4 5
5 2
5 3
5 4
4
2 4
3 84
4 38
5 96

output:

46

result:

ok 1 number(s): "46"

Test #2:

score: 0
Accepted
time: 2ms
memory: 4632kb

input:

8 16 8 4
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 1
1 5
2 6
3 7
4 8
5 1
6 2
7 3
8 4
6
1 29
2 34
3 41
5 7
6 26
7 94

output:

-23

result:

ok 1 number(s): "-23"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3880kb

input:

5 5 2 1
1 1
2 3
3 4
4 5
5 2
2
4 1000000
5 100000

output:

1100000

result:

ok 1 number(s): "1100000"

Test #4:

score: 0
Accepted
time: 11ms
memory: 9232kb

input:

10 20 1 2
1 4
1 7
2 2
2 4
3 6
3 3
4 8
4 7
5 7
5 1
6 9
6 2
7 9
7 3
8 8
8 6
9 7
9 8
10 10
10 2
8
3 92067840
4 2874502
5 36253165
6 70758738
7 4768969
8 16029185
9 16207515
10 44912151

output:

132484345

result:

ok 1 number(s): "132484345"

Test #5:

score: -100
Time Limit Exceeded

input:

30 900 1 2
2 25
8 21
22 16
26 29
12 24
1 8
7 14
22 27
27 20
5 24
21 21
21 10
30 28
5 16
12 3
16 1
21 2
24 23
24 14
9 7
9 18
20 22
6 1
30 3
11 6
2 17
18 13
28 20
5 15
26 16
9 14
30 23
4 23
4 2
9 5
21 29
1 30
12 14
16 27
28 22
15 7
23 10
13 16
1 15
22 9
13 12
30 18
10 5
25 28
3 17
30 30
7 17
11 24
12 ...

output:


result: