QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#167116 | #2989. 一双木棋 | Cidoai# | 0 | 0ms | 0kb | C++14 | 2.0kb | 2023-09-07 08:11:48 | 2023-09-07 08:11:49 |
answer
#include<cstdio>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
inline int read(){
int x=0;
int f=0,ch=0;
while(ch<48||ch>57) f=(ch=='-'),ch=getchar();
while(ch>47&&ch<58) x=(x<<3)+(x<<1)+(ch&15),ch=getchar();
return f?-x:x;
}
inline void write(int x,char end=' '){
if(x==0){
putchar('0');
putchar(end);
return;
}
if(x<0) putchar('-'),x=-x;
int ch[70]={0},cnt=0;
while(x){
ch[cnt++]=(int)(x%10);
x/=10;
}
while(cnt--) putchar(ch[cnt]+48);
putchar(end);
}
inline int max(int x,int y){return x>y?x:y;}
inline int min(int x,int y){return x<y?x:y;}
const int N=12;
int n,m;
int a[N][N],b[N][N];
int chess[N];
ll base[N];
map<ll,int> dp[2];
map<ll,bool> vis;
inline void init(){
base[1]=1;
for(int i=2;i<=10;++i) base[i]=base[i-1]*11;
n=read(),m=read();
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
a[i][j]=read();
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
b[i][j]=read();
}
}
}
inline void dec(ll x){
for(int i=1;i<=n;++i) chess[i]=0;
int cnt=1;
while(x){
chess[cnt++]=x%11;
x/=11;
}
}
inline ll enc(){
ll s=0;
for(int i=1;i<=n;++i) s+=base[i]*chess[i];
return s;
}
queue<ll> q;
inline void solve(){
for(int i=1;i<=n;++i) chess[i]=m;
ll state=enc();
dp[0][state]=dp[1][state]=0;
vis[state]=1;
q.push(state);
while(!q.empty()){
state=q.front();
q.pop();
dec(state);
for(int i=1;i<=n&&chess[i];++i){
if(chess[i]<=chess[i+1]) continue;
if(i==1&&chess[i]==1) return;
if(!vis[state-base[i]]){
dp[0][state-base[i]]=a[i][chess[i]]+dp[1][state];
dp[1][state-base[i]]=-b[i][chess[i]]+dp[0][state];
vis[state-base[i]]=1;
q.push(state-base[i]);
}
else{
dp[0][state-base[i]]=max(dp[0][state-base[i]],a[i][chess[i]]+dp[1][state]);
dp[1][state-base[i]]=min(dp[1][state-base[i]],-b[i][chess[i]]+dp[0][state]);
}
}
}
}
int main(){
freopen("chess.in","r",stdin);
freopen("chess.out","w",stdout);
init();
solve();
write(a[1][1]+dp[1][enc()]);
return 0;
}
詳細信息
Test #1:
score: 0
Dangerous Syscalls
input:
2 2 48316 18516 34352 3263 0 0 0 0
output:
result:
Test #2:
score: 0
Dangerous Syscalls
input:
2 2 75925 18128 38471 42651 53412 27561 35202 23268
output:
result:
Test #3:
score: 0
Dangerous Syscalls
input:
2 2 68736 95419 18197 87453 0 0 0 0
output:
result:
Test #4:
score: 0
Dangerous Syscalls
input:
3 3 30347 75845 36131 48118 6205 51826 7486 40480 58445 89340 63578 42185 78864 73882 44618 53322 6677 35054
output:
result:
Test #5:
score: 0
Dangerous Syscalls
input:
3 3 96942 46732 31592 65874 7883 73289 44414 59236 9197 0 0 0 0 0 0 0 0 0
output:
result:
Test #6:
score: 0
Dangerous Syscalls
input:
3 3 28852 97109 77805 45967 58092 74930 95287 65144 94993 95970 74589 85144 18946 50383 94031 79115 82328 32425
output:
result:
Test #7:
score: 0
Dangerous Syscalls
input:
5 5 55928 35560 62780 77747 93320 2289 92078 11794 37512 63980 31076 40385 93729 16608 84575 21616 36427 52988 35960 23350 70170 30827 6468 46707 74459 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
result:
Test #8:
score: 0
Dangerous Syscalls
input:
5 5 69957 90847 86904 93073 40245 28329 60126 87118 6014 47716 44211 82632 7048 25316 18026 35996 66957 93148 28942 76653 24567 48573 21080 27648 79677 39142 22319 55890 94565 5578 43866 63511 78176 77389 67802 3878 89158 53308 62879 79293 72274 15472 6456 52791 12740 79970 46577 95439 33488 75518
output:
result:
Test #9:
score: 0
Dangerous Syscalls
input:
8 8 86108 81572 62938 40758 11532 21392 3581 2504 21005 70268 95734 70594 56220 90574 91914 5991 38371 69652 23397 46886 40865 53758 18445 39947 2301 13696 50188 33660 76692 5028 28616 79962 5316 54006 78086 86163 74562 7894 6618 13992 57283 96786 75838 91328 24732 66214 68383 61101 83739 36224 7365...
output:
result:
Test #10:
score: 0
Dangerous Syscalls
input:
8 8 72263 8419 55507 20324 91755 52440 23833 40787 43896 76816 36755 55447 37493 25197 28806 8158 25187 67254 96533 11633 87146 19947 60933 61777 93331 60407 66650 81711 67421 75937 3204 31741 45644 25632 25607 79091 31101 58533 33858 39864 83305 9970 19125 98016 8962 25312 80555 98895 18430 43522 1...
output:
result:
Test #11:
score: 0
Dangerous Syscalls
input:
10 1 26741 44875 46290 5961 14706 99723 79560 57538 8382 9583 0 0 0 0 0 0 0 0 0 0
output:
result:
Test #12:
score: 0
Dangerous Syscalls
input:
10 1 8919 95688 93267 67099 7408 10592 47300 98255 90780 39444 25459 53053 67109 26951 85889 45189 75775 50663 66822 60054
output:
result:
Test #13:
score: 0
Dangerous Syscalls
input:
10 2 66632 75577 25326 3304 12313 50122 45692 8004 43057 30880 27358 24369 19875 28212 13557 85685 49418 78047 261 93322 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
result:
Test #14:
score: 0
Dangerous Syscalls
input:
10 2 25734 42462 8713 55503 20831 23987 70428 5903 83351 5980 83772 5612 42644 46237 43480 78535 19670 62712 53134 10822 39935 37169 12368 43173 12082 70592 94150 57635 92408 66732 34779 36045 36700 99138 18012 10524 94630 67847 53753 67290
output:
result:
Test #15:
score: 0
Dangerous Syscalls
input:
10 3 54823 79443 61975 38396 80442 36722 39245 81935 39586 29086 91631 43723 10958 41722 76983 24586 36385 93874 55653 63080 84968 34760 64396 3608 30891 84631 40934 82340 61893 46524 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
result:
Test #16:
score: 0
Dangerous Syscalls
input:
10 3 15434 56518 19173 63657 66591 25524 52687 46377 21073 25206 53123 66671 38596 34739 72614 96706 6021 85095 4124 89829 48403 38150 15093 18712 51382 24338 30286 47130 39038 3832 21965 29454 79841 14161 76084 5510 66024 38502 96571 85937 55212 56427 25329 62587 88640 41121 73634 66947 21217 32703...
output:
result:
Test #17:
score: 0
Dangerous Syscalls
input:
10 10 43160 45942 25141 50836 26666 78029 12721 4060 47766 38519 28905 65543 95241 88277 30507 45604 22707 25934 46518 13090 98505 23934 17519 85400 67853 49111 19614 75664 84998 98627 58475 42511 85657 39342 35060 66998 41228 16873 88181 36244 33724 98601 65211 64329 12231 25041 57657 33323 32086 9...
output:
result:
Test #18:
score: 0
Dangerous Syscalls
input:
10 10 70388 78095 16286 35188 72693 40763 98905 1023 65024 81842 53222 18629 20665 77097 41261 75861 40355 56217 80207 40759 77986 26227 84790 23663 93662 20282 61248 48145 68547 41170 64745 34107 19239 33868 8082 12212 50633 22908 30293 5248 33110 94868 72727 62632 96809 25113 85890 62667 43510 811...
output:
result:
Test #19:
score: 0
Dangerous Syscalls
input:
10 10 73014 81755 69006 80227 53814 27348 35895 72225 44812 88805 46580 26594 98521 91734 45006 95725 83991 93222 31280 42881 1930 4436 14909 30601 47389 69949 95259 44800 40302 49192 7321 87219 55625 68368 74472 97075 84918 24964 75871 34301 25844 4678 18311 10928 22967 77535 89398 18506 95071 6706...
output:
result:
Test #20:
score: 0
Dangerous Syscalls
input:
10 10 27529 95558 10391 83912 84199 11266 31322 29230 3717 17653 99818 93168 68278 68079 2991 59925 54348 68141 65949 46561 64979 83072 67821 31192 27141 9762 57620 88326 86972 90315 8756 61729 66442 11671 42697 15428 81717 40639 97733 75316 47835 12306 76669 33750 16018 7878 4065 57240 94357 18110 ...