QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#393076 | #7185. Poor Students | qwqUwU_ | WA | 4ms | 24508kb | C++14 | 2.3kb | 2024-04-18 08:43:17 | 2024-04-18 08:43:18 |
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],mp[K][K];
int vis[N],g[K][K];
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;
inline void get(int x,int y){
//printf("get(%d %d %d)\n",x,y,g[x][y]);
if(!~g[x][y]){vec.pb(x);return ;}
get(x,g[x][y]),get(g[x][y],y);
}
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){
int p=i*m+j;
while(!q[p].empty() && vis[q[p].top().se] != i)q[p].pop();
mp[i][j]=f[i][j]=q[p].empty()?1e14:q[p].top().fi;
g[i][j]=-1;
}
rep(k,0,m-1){
rep(i,0,k)rep(j,0,k)if(k!=i && k!=j && f[i][k]+f[k][j]<f[i][j])f[i][j]=f[i][k]+f[k][j],g[i][j]=k;
}
ll mn=1e15;int qa;
rep(i,0,m-1)if(f[i][i]<mn)qa=i,mn=f[i][i];
if(mn>=0)break;
vec.clear();get(qa,qa);vec.pb(qa);
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("mn=%lld\n",mn);
}
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 24508kb
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: 4ms
memory: 23948kb
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: 3ms
memory: 24208kb
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:
-211133
result:
wrong answer expected '92039', found '-211133'