QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#176764#6331. Jewel Gameucup-team1209WA 889ms13860kbC++143.2kb2023-09-11 23:47:142023-09-11 23:47:15

Judging History

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

  • [2023-09-11 23:47:15]
  • 评测
  • 测评结果:WA
  • 用时:889ms
  • 内存:13860kb
  • [2023-09-11 23:47:14]
  • 提交

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[sz*sz]; int type[sz*sz];
unordered_set<int>V1[sz*sz];
int deg[sz*sz];

priority_queue<pair<ll,int>>S;

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

void solve() {
	while (S.size()) S.pop();
	rep(i,0,N-1) S.push({f[i],i});
	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][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=n*n;
		memset(f,~0x3f,sizeof(f));
		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=i*n+j;
			rep(k,0,n-1) if (e[i][k]) {
				if (id[k]==-1||!(s>>id[k]&1)) {
					int y=j*n+k;
					++deg[x],V1[y].insert(x);
				}
				else {
					ll ww=w[id[k]];
					ww-=dp[1<<id[k]^s][j][k];
					chkmax(f[x],ww);
				}
			}
		}
		solve();
		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=i*n+j;
			dp[s][i][j]=f[x];
			V1[x]=unordered_set<int>(),deg[x]=del[x]=0;
		}
	}
	cout<<dp[(1<<K)-1][A][B]<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 4060kb

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: 3728kb

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: 4ms
memory: 6136kb

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: 0
Accepted
time: 889ms
memory: 13860kb

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:

40915541

result:

ok 1 number(s): "40915541"

Test #6:

score: 0
Accepted
time: 889ms
memory: 13736kb

input:

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

output:

38892888

result:

ok 1 number(s): "38892888"

Test #7:

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

input:

9 58 5 4
4 6
8 9
5 3
6 5
7 1
5 9
6 3
2 1
4 8
2 9
3 4
1 2
8 5
5 2
1 3
2 3
9 5
4 3
3 1
5 4
9 1
6 7
2 8
7 3
2 5
8 3
2 7
5 8
4 7
9 2
4 5
5 7
3 7
6 8
1 4
9 4
9 8
7 9
1 1
4 4
3 6
1 8
6 6
5 5
9 9
5 1
1 6
2 4
3 2
5 6
3 3
2 6
7 4
6 2
3 9
6 9
8 8
9 7
2
1 28323506
7 18381394

output:

46704900

result:

ok 1 number(s): "46704900"

Test #8:

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

input:

8 11 4 4
4 6
7 6
8 2
5 8
3 4
2 3
8 6
5 1
6 6
1 8
8 4
4
2 75547123
5 9278878
7 13909469
8 57425260

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

4 10 1 2
2 3
1 3
4 4
1 4
3 3
4 3
1 2
3 1
2 4
1 1
2
3 35669800
4 36664186

output:

994386

result:

ok 1 number(s): "994386"

Test #10:

score: 0
Accepted
time: 13ms
memory: 6812kb

input:

17 125 15 14
12 5
13 11
13 12
9 13
16 2
13 3
1 14
16 14
13 10
3 2
17 14
14 12
8 11
10 1
9 8
14 2
13 6
3 3
7 1
11 12
16 17
10 4
15 10
12 11
10 10
4 9
14 16
9 3
4 8
15 5
2 12
7 11
14 1
10 3
4 11
4 4
8 12
8 7
9 16
15 13
17 9
1 10
8 5
13 4
13 16
15 15
9 10
17 4
10 17
2 16
13 1
15 9
5 7
14 11
10 9
5 5
9 ...

output:

-33927098

result:

ok 1 number(s): "-33927098"

Test #11:

score: -100
Wrong Answer
time: 1ms
memory: 3932kb

input:

11 18 8 7
5 11
9 3
1 8
6 11
11 5
5 9
1 9
2 5
10 2
4 10
7 1
6 2
10 8
3 9
8 6
3 7
7 11
2 10
5
2 22754552
5 84549882
6 19922948
9 13449629
11 18334746

output:

0

result:

wrong answer 1st numbers differ - expected: '-73656757', found: '0'