QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#134776 | #5371. Matrix | masterhuang | 0 | 1ms | 3552kb | C++20 | 2.3kb | 2023-08-04 21:50:28 | 2023-08-04 21:50:30 |
Judging History
answer
//qoj 5371
//https://qoj.ac/problem/5371
#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=105,M=2505;
int TOT,n,a[N][N],b[N],c[N],tot=1,head[N],_head[N],d[N],S,T,tt,as[M][N];
struct edge{int to,nex,w;}e[M<<1];
inline void add(int u,int v,int w)
{
e[++tot]={v,head[u],w};head[u]=tot;
e[++tot]={u,head[v],0};head[v]=tot;
}
inline bool bfs()
{
queue<int>q;memset(d,0,sizeof(d));d[S]=1;q.push(S);
while(!q.empty())
{
int t=q.front();q.pop();
for(int i=head[t];i;i=e[i].nex)
{
int to=e[i].to;
if(!d[to]&&e[i].w>0) d[to]=d[t]+1,q.push(to);
}
}return d[T];
}
int dfs(int x,int flow)
{
if(x==T) return flow;int old=flow;
for(int &i=_head[x];i;i=e[i].nex)
{
int to=e[i].to;
if(d[to]==d[x]+1&&e[i].w>0)
{
int nw=dfs(to,min(e[i].w,flow));flow-=nw;
e[i].w-=nw,e[i^1].w+=nw;
if(!flow) break;
}
}return (flow==old)&&(d[x]=0),old-flow;
}
inline int dinic(){int ans=0;while(bfs()) memcpy(_head,head,sizeof(head)),ans+=dfs(S,1e9);return ans;}
inline bool chk(){for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][j]) return 1;return 0; }
inline void sol()
{
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][j]<0) return cout<<"-1\n",void();
for(int i=1,s=0;i<=n;i++,s=0){for(int j=1;j<=n;j++) s+=a[i][j];b[i]=s;}
for(int i=1,s=0;i<=n;i++,s=0){for(int j=1;j<=n;j++) s+=a[j][i];b[i+n]=s;}
for(int i=1;i<2*n;i++) if(b[i]^b[i+1]) return cout<<"-1\n",void();S=0;T=2*n+1;tt=0;
while(chk())
{
tot=1;memset(head,0,sizeof(head));
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(a[i][j]) add(i,n+j,1);
for(int i=1;i<=n;i++) add(S,i,1),add(i+n,T,1);int ans=dinic();
for(int i=1;i<=n;i++) for(int j=head[i];j;j=e[j].nex) if(!e[j].w&&e[j].to){c[i]=e[j].to-n;break;}
int mn=1e9;for(int i=1;i<=n;i++) mn=min(mn,a[i][c[i]]);as[++tt][0]=mn;
for(int i=1;i<=n;i++) a[i][c[i]]-=mn,as[tt][i]=c[i],cout<<tt<<" "<<i<<":"<<c[i]<<"\n";
}cout<<tt<<"\n";
if(n==50) exit(0);
for(int i=1;i<=tt;i++,cout<<"\n") for(int j=0;j<=n;j++) cout<<as[i][j]<<" ";
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>TOT;
while(TOT--){cin>>n;for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j];sol();}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3552kb
input:
10 5 41 18467 6334 26500 2995 19169 15724 11478 29358 -21392 26962 24464 5705 28145 -30939 23281 16827 9961 491 3777 -15116 -21145 20859 -30157 99896 5 4827 5436 32391 14604 1869 3902 153 292 12382 42398 17421 18716 19718 19895 -16623 5447 21726 14771 11538 5645 27530 13096 -8045 708 25838 5 41879 4...
output:
-1 -1 1 1:1 1 2:2 1 3:3 1 4:4 1 5:5 2 1:1 2 2:2 2 3:3 2 4:5 2 5:4 3 1:1 3 2:3 3 3:2 3 4:5 3 5:4 4 1:5 4 2:3 4 3:2 4 4:1 4 5:4 5 1:2 5 2:3 5 3:1 5 4:5 5 5:4 6 1:5 6 2:2 6 3:1 6 4:3 6 5:4 7 1:5 7 2:2 7 3:1 7 4:4 7 5:3 8 1:2 8 2:1 8 3:5 8 4:4 8 5:3 9 1:5 9 2:4 9 3:1 9 4:2 9 5:3 10 1:5 10 2:4 10 3:1 10 ...
result:
wrong output format Expected integer, but "1:1" found (test case 3)
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%