QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#75764 | #5308. RPG Pro League | 275307894a | WA | 209ms | 9276kb | C++14 | 2.6kb | 2023-02-06 10:06:42 | 2023-02-06 10:06:46 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define PB push_back
using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned ll;
using namespace std;const int N=1e5+5,M=(1<<21)+5,K=2e3+5,mod=924844033,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int Ct,S,T,n,m,x,y,A[N],op[N];ll Ans;string c;map<string,int> op_to_op;multiset<int> f1[8],f2[8];
int g[20][20],w[20][20],vis[20],pre[20],G[20];ll D[20];
void BD(){
int i,j;for(i=1;i<=7;i++) {
if(f1[i].size()) w[S][i]=*f1[i].begin(),g[S][i]=1;else g[S][i]=0;
if(f2[i].size()) w[i][S]=*f2[i].begin(),g[i][S]=1;else g[i][S]=0;
}
}
queue<int> Q;int BFS(){
while(!Q.empty()) Q.pop();BD();Me(G,0);Me(D,0x3f);D[S]=0;G[S]=INF;Q.push(S);while(!Q.empty()){
int x=Q.front();Q.pop();for(int i=S;i<=T;i++) if(g[x][i]&&D[i]>D[x]+w[x][i]) {
D[i]=D[x]+w[x][i];G[i]=min(G[x],g[x][i]);pre[i]=x;if(i==S) return -1;Q.push(i);
}
}return G[T]>0;
}
void Ers(int x,int y){
if(x==S) f1[y].erase(f1[y].LB(w[x][y])),f2[y].insert(-w[x][y]);
else if(y==S)f2[x].erase(f2[x].LB(w[x][y])),f1[x].insert(-w[x][y]);
else g[x][y]--,g[y][x]++;
}
int main(){
op_to_op["D"]=1;op_to_op["S"]=2;op_to_op["B"]=3;op_to_op["DS"]=4;op_to_op["BD"]=5;op_to_op["BS"]=6;op_to_op["BDS"]=7;
int i,j,h;scanf("%d",&n);for(i=1;i<=n;i++){
cin>>c;sort(c.begin(),c.end());op[i]=op_to_op[c],scanf("%d",&A[i]),f1[op[i]].insert(A[i]);
}
S=0;T=12;g[1][8]=g[1][11]=g[2][9]=g[2][11]=g[3][10]=g[4][8]=g[4][9]=g[4][11]=g[5][8]=g[5][10]=g[5][11]=g[6][9]=g[6][10]=g[6][11]=g[7][8]=g[7][9]=g[7][10]=g[7][11]=INF;
Ct=INF;for(i=0;i<(1<<4);i++){
Me(vis,0);for(j=1;j<=7;j++) for(h=8;h<=11;h++) if(i>>(h-8)&1) vis[j]=1;
int C1=0,C2=0;for(j=0;j<4;j++) if(i>>j&1) C1++;for(j=1;j<=7;j++) if(vis[j]) C2+=f1[j].size();
if(C1)Ct=min(Ct,C2/C1);
}
for(i=8;i<=11;i++) g[i][T]=Ct;
int p;while(p=BFS()) {
if(p==1){Ans+=D[T];p=T;while(p^S) Ers(pre[p],p),p=pre[p];}
else {Ans+=D[S];p=S;do {Ers(pre[p],p);p=pre[p];}while(p^S);}
}
scanf("%d",&m);while(m--){
scanf("%d%d",&x,&y);
if(f1[op[x]].count(A[x])) f1[op[x]].erase(f1[op[x]].LB(A[x])),f1[op[x]].insert(A[x]=y);
else f2[op[x]].erase(f2[op[x]].LB(-A[x])),Ans+=y-A[x],f2[op[x]].insert(-(A[x]=y));
while(p=BFS()) {
if(p==1){Ans+=D[T];p=T;while(p^S) Ers(pre[p],p),p=pre[p];}
else {Ans+=D[S];p=S;do {Ers(pre[p],p);p=pre[p];}while(p^S);}
}printf("%lld\n",Ans);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3832kb
input:
5 BS 3 D 3 B 2 D 4 D 5 2 5 2 1 5
output:
10 12
result:
ok 2 number(s): "10 12"
Test #2:
score: -100
Wrong Answer
time: 209ms
memory: 9276kb
input:
100000 B 727564174 S 231637747 D 246625257 S 975124756 D 844292741 S 809641006 B 396062588 B 883224128 B 311130283 S 434433581 S 509817048 S 993501344 S 508399542 B 279564062 D 950946642 D 819528264 D 412285620 B 968540732 S 953428318 D 902181790 S 172330493 D 725075 B 135580649 D 714478555 B 466916...
output:
42697773021480 42696943708470 42697126431296 42696645477830 42696952519393 42696469532179 42695603517350 42696007620237 42696076141695 42696796662544 42697069392730 42697619585053 42698158432933 42698056605680 42698970152809 42699425405426 42698640034503 42698288864720 42698078017285 42697284857365 ...
result:
wrong answer 1st numbers differ - expected: '40721766963064', found: '42697773021480'