QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#393110 | #7185. Poor Students | qwqUwU_ | WA | 0ms | 25220kb | C++20 | 2.2kb | 2024-04-18 10:09:30 | 2024-04-18 10:09:30 |
Judging History
answer
// clang-format off
#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define bit(s,x) (((s)>>(x))&1)
#define pnp(s) __builtin_popcountll(s)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
mt19937 gen(time(0));
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii; typedef pair<ll,int> pli; typedef pair<ll,ll> pll; typedef pair<int,ll> pil;
inline ll read(){
ll x=0,f=1,c=getchar();
while(c<'0'||c>'9')f=(c=='-'?-1:1),c=getchar();
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
const int mod=998244353;
inline int fp(int x,ll p=mod-2,int m=mod,int res=1){
for(;p;p>>=1){if(p&1)res=1ll*res*x%m;x=1ll*x*x%m;}
return res;
}
const int N=5e5+3;
const int K=10;
priority_queue<pii,vector<pii>,greater<pii>>q[K*K];
// clang-format on
int n,m,c[N][K],a[K];
ll ans,f[K][K];
int vis[N];
inline void update(int x,int y){
vis[x]=y;
rep(k,0,m-1)if(y!=k) q[y*m+k].push(P(c[x][k]-c[x][y],x));
}
vector<int>vec,v2;ll mn;
bool inq[K];
inline void dfs(int u,int rt,ll dis){
inq[u]=1;v2.pb(u);
if(u!=rt){
if(~f[u][rt] && mn > dis + f[u][rt]){
mn=dis + f[u][rt];
vec=v2;vec.pb(rt);
}
}
rep(i,0,m-1)if(!inq[i] && ~f[u][i])dfs(i,rt,dis+f[u][i]);
v2.pop_back();
}
int main() {
//freopen("data.in", "r", stdin);
// freopen(".in","r",stdin);
// freopen("myans.out","w",stdout);
n=read(),m=read();
memset(c,0x7f,sizeof c);
rep(i,1,n)rep(j,0,m-1)c[i][j]=read();
int tot=0;
rep(j,0,m-1){
a[j]=read();
rep(k,1,a[j]){
++tot;
if(tot<=n)ans += c[tot][j];
update(tot,j);
}
}
while(1){
rep(i,0,m-1)rep(j,0,m-1)if(i!=j){
int p=i*m+j;
while(!q[p].empty() && vis[q[p].top().se] != i)q[p].pop();
f[i][j]=q[p].empty()?-1:q[p].top().fi;
}
mn=1e15;vec.clear();
rep(i,0,m-1){
rep(j,0,m-1)inq[j]=0;
dfs(i,i,0);
}
if(mn>=0)break;
ll old=ans;
rep(i,0,vec.size()-2){
int x=vec[i],y=vec[i+1],p=x*m+y;
ans += q[p].top().fi;
update(q[p].top().se,y);
//q[p].pop();
}
//assert(ans-old==mn);
//printf("%lld %lld\n",mn,ans);
}
cout<<ans;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 23736kb
input:
6 2 1 2 1 3 1 4 1 5 1 6 1 7 3 4
output:
12
result:
ok answer is '12'
Test #2:
score: 0
Accepted
time: 0ms
memory: 24644kb
input:
3 3 1 2 3 2 4 6 6 5 4 1 1 1
output:
8
result:
ok answer is '8'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 25220kb
input:
1000 10 734 303 991 681 755 155 300 483 702 442 237 256 299 675 671 757 112 853 759 233 979 340 288 377 718 199 935 666 576 842 537 363 592 349 494 961 864 727 84 813 340 78 600 492 118 421 478 925 552 617 517 589 716 7 928 638 258 297 706 787 266 746 913 978 436 859 701 951 137 44 815 336 471 720 2...
output:
118304
result:
wrong answer expected '92039', found '118304'