QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209759 | #6331. Jewel Game | c20231020 | AC ✓ | 282ms | 8692kb | C++23 | 9.5kb | 2023-10-10 17:05:42 | 2023-10-10 17:05:43 |
Judging History
answer
/*
膜拜传奇特级宗师 Afterglow 大神儿
今天在 florr 首页称您为大夏尊贵的大名儿
一股敬佩之情油生然而
您在 florr 为国争光,扬我大夏威名
向您献上最真挚的膜拜!!!
膜拜传奇特级宗师 Afterglow 大神儿,今,一,您,扬。向!
膜拜传奇特级宗师 Afterglow 大神儿,今,一,您,扬。向!
膜拜传奇特级宗师 Afterglow 大神儿,今,一,您,扬。向!
*/
/*
_____ _____ _____ _____
/\ \ /\ \ /\ \ /\ \
/ \ \ / \ \ / \____\ / \ \
\ \ \ / \ \ / / / \ \ \
\ \ \ / \ \ / / / \ \ \
\ \ \ / /\ \ \ / /____/ \ \ \
\ \ \ / / \ \ \ / | | \ \ \
\ \ \ / / \ \ \ / | | \ \ \
\ \ \ / / / \ \ \ / | | \ \ \
\ \ \ / / / \ \ \ / |____|__ _____ \ \ \
_______________\ \____\/ /____/ \ \ \ / /| \ \ _______________\ \____\
\ / /\ \ \ \ \ \\ / | _________\____\\ / /
\ ____________/____/ \ \ \ \ \____\\/__| | | \ ____________/____/
\ \ \ \ \ \ | | | | | | \ \ \
\ \ \ \ \ \ | | | | | | \ \ \
\ \ \ \ \ \ | |____| | | | \ \ \
\ \ \ \ \ \ / / / \ | | \ \ \
\ \ \ \ \ \/ / / \ | | \ \ \
\ \____\ \ \___/ / / \ | | \ \____\
\ / / \ / / \| | \ / /
\/____/ \_______/____/ \____| \/____/
*/
#define poj
#define zcz
#ifdef poj
//C++
#include<iomanip>
#include<iostream>
//C
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
//STL
#include<algorithm>
#include<bitset>
#include<functional>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
//C++11
#if __cplusplus>=201103L
#include<chrono>
#include<random>
#include<unordered_set>
#include<unordered_map>
#endif
#else
#include<bits/stdc++.h>
#endif
using namespace std;
#ifdef zcz
class fastin{
private:
#ifdef poj
static const int MAXBF=1<<20;
#else
const int MAXBF=1<<27;
#endif
FILE *inf;
char *inbuf,*inst,*ined;
inline char _getchar(){
if(inst==ined)inst=inbuf,ined=inbuf+fread(inbuf,1,MAXBF,inf);
return inst==ined?EOF:*inst++;
}
public:
fastin(FILE*_inf=stdin){
inbuf=new char[MAXBF],inf=_inf,inst=inbuf,ined=inbuf;
}
~fastin(){delete[]inbuf;}
template<typename Int> fastin&operator>>(Int &n){
static char c;
Int t=1;
while((c=_getchar())<'0'||c>'9')if(c=='-')t=-1;
n=(c^48);
while((c=_getchar())>='0'&&c<='9')n=n*10+(c^48);
n*=t;
return *this;
}
fastin&operator>>(char&c){
while((c=_getchar())<'!'||c>'~');
return *this;
}
fastin&operator>>(char*s){
int t=0;
static char c;
while((c=_getchar())==' '||c=='\n');
s[t++]=c;
while((c=_getchar())>='!'&&c<='~')s[t++]=c;
s[t]='\0';
return *this;
}
}fi;
class fastout{
private:
#ifdef poj
static const int MAXBF=1<<20;
#else
const int MAXBF=1<<27;
#endif
FILE *ouf;
char *oubuf,*oust,*oued;
inline void _flush(){fwrite(oubuf,1,oued-oust,ouf);oued=oust;}
inline void _putchar(char c){
if(oued==oust+MAXBF)_flush(),oued=oubuf;
*oued++=c;
#ifdef local
_flush();
#endif
}
public:
fastout(FILE*_ouf=stdout){
oubuf=new char[MAXBF],ouf=_ouf,oust=oubuf,oued=oubuf;
}
~fastout(){_flush();delete[]oubuf;}
template<typename Int> fastout&operator<<(Int n){
if(n<0)_putchar('-'),n=-n;
static char S[20];
int t=0;
do{S[t++]='0'+n%10,n/=10;}while(n);
for(int i=0;i<t;++i)_putchar(S[t-i-1]);
return *this;
}
fastout&operator<<(char c){_putchar(c);return *this;}
fastout&operator<<(char*s){
for(int i=0;s[i];++i)_putchar(s[i]);
return *this;
}
fastout&operator<<(const char*s){
for(int i=0;s[i];++i)_putchar(s[i]);
return *this;
}
}fo;
#define cin fi
#define cout fo
#else
#define czc ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#endif
#define mod7 1000000007
#define mod9 998244353
#define ll long long
#define isinf 0x3f3f3f3f
#define ilinf 0x7fffffff
#define lsinf 0x3f3f3f3f3f3f3f3f
#define llinf 0x7fffffffffffffff
#define pii pair<int,int>
#define fr first
#define sc second
#define next ___
#define pb push_back
#define N 35
#define M 5000010
#define For(i,a,b) for(ll i=(a);i<=(b);++i)
#define Rep(i,a,b,c) for(ll i=(a);i<=(b);i+=c)
#define Per(i,a,b,c) for(ll i=(a);i>=(b);i-=c)
#define Gra(i) for(ll i=h[x];i;i=next[i])
typedef int arr[N];
typedef int arm[M];
typedef ll arl[N];
typedef ll alm[M];
typedef double ard[N];
typedef double adm[M];
namespace modint{
template<typename Int,Int mod,Int m1>
struct modint{
Int v;
modint(){v=0;}
modint(Int a){v=a;}
bool operator==(modint a){return v==a.v;}
bool operator!=(modint a){return v!=a.v;}
bool operator<(modint a){return v<a.v;}
bool operator>(modint a){return v>a.v;}
bool operator<=(modint a){return v<=a.v;}
bool operator>=(modint a){return v>=a.v;}
bool operator==(Int a){return v==a;}
bool operator!=(Int a){return v!=a;}
bool operator<(Int a){return v<a;}
bool operator>(Int a){return v>a;}
bool operator<=(Int a){return v<=a;}
bool operator>=(Int a){return v>=a;}
friend bool operator==(Int a,modint b){return b==a;}
friend bool operator!=(Int a,modint b){return b!=a;}
friend bool operator<(Int a,modint b){return b>a;}
friend bool operator>(Int a,modint b){return b<a;}
friend bool operator<=(Int a,modint b){return b>=a;}
friend bool operator>=(Int a,modint b){return b<=a;}
modint operator+(modint a){return v>=mod-a.v?v-mod+a.v:v+a.v;}
modint operator-(modint a){return v>=a.v?v-a.v:v+mod-a.v;}
modint modnum(modint a){
return a-((__int128(a.v)*m1)>>80)*mod;
}
modint operator*(modint a){return modnum(v*a.v);}
modint operator+=(modint a){*this=*this+a;return *this;}
modint operator-=(modint a){*this=*this-a;return *this;}
modint operator*=(modint a){*this=*this*a;return *this;}
modint qpow(modint a,Int b){
modint r(1);
for(;b;b>>=1,a*=a)if(b&1)r*=a;
return r;
}
modint operator/(modint a){return qpow(a,mod-2)*v;}
modint operator/=(modint a){*this=*this/a;return *this;}
modint&operator++(){*this=*this+1;return *this;}
modint&operator--(){*this=*this-1;return *this;}
const modint operator++(int){modint r=*this;++*this;return r;}
const modint operator--(int){modint r=*this;--*this;return r;}
friend modint operator+(Int a,modint b){return b+a;}
friend modint operator-(Int a,modint b){return b-a;}
friend modint operator*(Int a,modint b){return b*a;}
friend modint operator/(Int a,modint b){return modint(a)/b;}
#ifdef cout
friend fastin&operator>>(fastin&in,modint&n){in>>n.v;return in;}
friend fastout&operator<<(fastout&out,modint n){out<<n.v;return out;}
#else
friend istream&operator>>(istream&in,modint&n){in>>n.v;return in;}
friend ostream&operator<<(ostream&out,modint n){out<<n.v;return out;}
#endif
};
typedef modint<long long,1000000007,1208925811152148> int7;
typedef modint<long long,998244353,1211051999424262> int9;
}
using namespace modint;
int n,m,s,t,k,id[N],a[N],f[1<<10|1][N][N],d[N][N],vis[N][N],mn[N][N];
vector<int>e[N];
vector<pii>p[N][N];
void re(int s,int x,int y){
f[s][x][y]=-mn[x][y];
vis[x][y]=1;
for(auto [i,j]:p[x][y]){
mn[i][j]=min(mn[i][j],f[s][x][y]);
if(!--d[i][j]&&!vis[i][j]){
re(s,i,j);
}
}
}
void solve(){
cin>>n>>m>>s>>t;
For(i,1,m){
int x,y;
cin>>x>>y;
e[x].pb(y);
};
cin>>k;
fill(id+1,id+1+n,k+1);
For(i,1,k){
int v,w;
cin>>v>>w;
a[i]=w;
id[v]=i;
};
For(s,0,(1<<k)-1){
For(i,1,n){
For(j,1,n){
vis[i][j]=d[i][j]=0;
p[i][j].clear();
};
};
For(i,1,n)if(!((s>>(id[i]-1))&1)){
For(j,1,n)if(!((s>>(id[j]-1))&1)){
mn[i][j]=isinf;
for(int x:e[i]){
if((s>>(id[x]-1))&1){
mn[i][j]=min(mn[i][j],f[s^(1<<(id[x]-1))][j][x]-a[id[x]]);
}else{
p[j][x].pb({i,j});
++d[i][j];
}
}
};
};
For(i,1,n){
For(j,1,n){
if(!d[i][j]&&!vis[i][j]){
re(s,i,j);
}
};
};
for(;;){
int x=0,y=0,tem=0;
For(i,1,n){
For(j,1,n){
if(!vis[i][j]&&mn[i][j]<tem){
tem=mn[i][j];
x=i;y=j;
}
};
};
if(!tem)break;
re(s,x,y);
}
For(i,1,n){
For(j,1,n){
if(d[i][j]>0){
f[s][i][j]=0;
}
};
};
};
cout<<f[(1<<k)-1][s][t];
return;
}
int main(){
#ifndef zcz
czc;
#endif
int t=1;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3536kb
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: 3656kb
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: 3612kb
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: 2ms
memory: 4568kb
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: 228ms
memory: 8636kb
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: 230ms
memory: 8644kb
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: 3456kb
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: 5592kb
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: 3604kb
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: 5ms
memory: 4300kb
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: 0
Accepted
time: 1ms
memory: 3752kb
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:
-73656757
result:
ok 1 number(s): "-73656757"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3416kb
input:
3 8 2 3 1 3 3 2 1 2 3 3 2 1 2 3 3 1 2 2 1 1 53102229
output:
53102229
result:
ok 1 number(s): "53102229"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
3 6 1 1 1 3 2 3 3 1 2 2 1 2 2 1 1 3 88674071
output:
88674071
result:
ok 1 number(s): "88674071"
Test #14:
score: 0
Accepted
time: 1ms
memory: 5728kb
input:
10 22 3 3 5 6 2 9 1 4 6 4 7 9 3 4 4 3 4 2 6 3 10 8 8 1 8 2 9 4 5 10 4 10 7 3 7 6 10 9 1 1 1 10 10 5 2 3 4 1 12017417 2 33560186 9 68408625 10 44302781
output:
91168637
result:
ok 1 number(s): "91168637"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
11 76 11 6 11 9 4 8 4 2 11 4 7 7 9 8 5 2 7 3 1 4 8 8 6 1 2 7 7 4 9 6 10 6 7 9 3 5 1 8 2 11 1 6 4 1 10 2 4 11 4 4 2 8 8 9 11 10 8 4 8 5 3 4 4 5 11 5 11 8 10 3 8 3 7 6 4 9 1 7 1 10 7 5 10 4 5 6 6 10 5 5 7 11 8 11 2 2 6 9 1 5 2 3 8 1 3 10 6 3 9 10 5 8 7 10 1 11 4 3 2 9 5 10 9 5 3 1 5 7 6 5 9 3 5 11 3 6...
output:
18844044
result:
ok 1 number(s): "18844044"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
5 8 2 5 5 4 4 1 3 5 1 5 1 2 2 5 3 3 3 1 3 1 89861734 3 78638917 4 76333187
output:
-166194921
result:
ok 1 number(s): "-166194921"
Test #17:
score: 0
Accepted
time: 25ms
memory: 8388kb
input:
24 34 21 10 17 17 19 21 22 24 8 4 10 11 7 11 18 20 9 15 17 7 2 8 5 4 13 6 11 5 21 11 12 16 7 23 3 13 16 7 1 3 23 18 6 2 20 24 19 20 14 13 15 9 2 14 4 24 24 1 1 4 5 12 11 22 14 23 2 20 8 15 10 4 32206739 5 86258057 6 28124909 8 30711780 17 1439605 18 98665106 19 35462765 20 42495740 22 94507837 23 65...
output:
107651072
result:
ok 1 number(s): "107651072"
Test #18:
score: 0
Accepted
time: 18ms
memory: 4016kb
input:
25 157 7 9 12 18 16 14 7 14 4 11 24 20 19 4 19 6 17 4 12 16 21 14 18 25 22 10 15 3 14 11 5 16 15 9 24 13 10 14 25 1 25 22 25 8 18 20 17 11 12 21 2 6 14 14 18 13 17 7 9 16 13 21 16 25 17 8 21 2 19 2 15 4 10 8 15 11 20 21 13 1 7 11 9 11 20 12 7 10 15 12 16 16 2 22 21 17 21 3 16 9 22 1 6 24 9 23 12 10 ...
output:
27571523
result:
ok 1 number(s): "27571523"
Test #19:
score: 0
Accepted
time: 282ms
memory: 8644kb
input:
30 594 3 3 21 8 13 27 26 24 17 20 10 1 24 14 30 26 7 22 14 3 16 1 15 28 2 20 5 23 23 16 24 6 4 29 19 24 25 13 19 13 24 27 16 3 18 19 5 18 1 30 29 18 1 8 30 6 10 16 30 3 29 10 23 17 17 2 16 2 1 16 3 1 22 19 5 17 4 14 19 23 9 29 22 16 18 15 2 25 10 9 28 7 12 12 2 10 10 19 3 6 15 19 6 21 7 23 23 24 4 1...
output:
20858678
result:
ok 1 number(s): "20858678"
Test #20:
score: 0
Accepted
time: 244ms
memory: 8488kb
input:
30 194 4 8 16 26 23 10 12 22 18 9 9 21 17 24 14 18 4 26 4 17 12 25 16 6 6 24 27 3 17 17 5 6 8 25 5 18 8 1 19 5 14 21 16 7 1 23 11 11 19 27 8 5 5 8 25 28 4 1 28 17 19 25 25 1 23 24 2 9 17 26 15 10 9 11 5 30 22 24 20 2 16 19 9 19 12 12 30 8 22 16 14 11 16 17 7 29 12 18 23 23 5 24 1 14 26 19 19 14 25 5...
output:
42920444
result:
ok 1 number(s): "42920444"
Test #21:
score: 0
Accepted
time: 68ms
memory: 8572kb
input:
30 59 11 13 2 5 18 16 9 19 5 22 30 4 23 8 3 9 17 28 12 28 12 13 7 1 17 16 7 28 22 6 22 21 23 16 8 27 27 14 4 4 3 21 1 27 22 11 15 6 7 3 26 26 29 15 15 12 4 14 21 9 24 2 13 11 3 22 18 20 29 10 11 16 26 19 10 8 20 23 15 2 20 2 19 12 20 10 15 15 25 8 10 24 1 24 9 10 16 17 3 25 9 8 25 17 14 7 14 28 8 26...
output:
235374574
result:
ok 1 number(s): "235374574"
Test #22:
score: 0
Accepted
time: 153ms
memory: 8436kb
input:
30 91 15 24 17 26 26 4 7 19 22 15 1 7 17 27 21 24 29 15 12 22 10 16 18 2 1 3 25 7 16 27 21 8 25 10 16 19 8 25 14 24 7 9 5 4 11 22 8 4 21 26 23 22 21 12 14 29 20 27 5 23 7 16 29 7 2 26 9 27 2 11 12 29 20 1 30 3 24 11 3 26 8 17 13 12 5 22 28 15 24 6 22 29 23 16 19 1 9 20 1 11 4 5 2 4 6 23 13 29 11 14 ...
output:
57866396
result:
ok 1 number(s): "57866396"
Test #23:
score: 0
Accepted
time: 150ms
memory: 8376kb
input:
30 74 24 24 25 11 14 15 23 23 2 13 6 26 27 14 30 14 11 10 26 16 3 27 20 10 21 5 19 10 14 1 4 11 10 27 20 24 6 23 5 14 25 28 27 12 24 7 17 10 13 4 30 27 12 25 22 27 20 25 29 20 17 29 23 13 22 23 16 20 20 4 28 20 13 12 18 27 7 30 1 28 18 1 30 23 2 8 6 30 27 19 16 26 24 21 3 8 28 13 28 4 14 5 19 21 23 ...
output:
30736171
result:
ok 1 number(s): "30736171"
Test #24:
score: 0
Accepted
time: 282ms
memory: 8692kb
input:
30 542 11 11 19 24 24 14 25 25 11 6 30 21 14 19 19 9 2 22 9 19 21 5 23 27 27 15 14 10 13 3 22 5 3 5 28 14 22 13 14 22 22 7 11 22 23 19 27 12 6 11 24 25 23 17 26 28 27 24 10 29 5 30 17 17 29 7 28 4 6 17 6 30 20 19 2 2 18 22 3 29 7 12 27 28 25 18 30 23 22 15 11 19 10 28 2 7 4 4 11 20 2 11 11 14 23 7 2...
output:
50977437
result:
ok 1 number(s): "50977437"