QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#75758#5308. RPG Pro League275307894aRE 0ms3756kbC++142.6kb2023-02-06 10:00:102023-02-06 10:00:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-06 10:00:13]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3756kb
  • [2023-02-06 10:00:10]
  • 提交

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=1e4+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) {
		int p=*f1[y].begin();f1[y].erase(f1[y].begin());f2[y].insert(-p);
	}else if(y==S){
		int p=*f2[x].begin();f2[x].erase(f2[x].begin());f1[x].insert(-p);
	}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: 0ms
memory: 3756kb

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
Runtime Error

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:


result: