Submission #2851403
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
template<class V> class MaxFlow_dinic {
public:
struct edge { int to,reve;V cap;};
static const int MV = 101010;
vector<edge> E[MV];
int itr[MV],lev[MV];
void add_edge(int x,int y,V cap,bool undir=false) {
E[x].push_back((edge){y,(int)E[y].size(),cap});
E[y].push_back((edge){x,(int)E[x].size()-1,undir?cap:0});
}
void bfs(int cur) {
MINUS(lev);
queue<int> q;
lev[cur]=0;
q.push(cur);
while(q.size()) {
int v=q.front(); q.pop();
ITR(e,E[v]) if(e->cap>0 && lev[e->to]<0) lev[e->to]=lev[v]+1, q.push(e->to);
}
}
V dfs(int from,int to,V cf) {
if(from==to) return cf;
for(;itr[from]<E[from].size();itr[from]++) {
edge* e=&E[from][itr[from]];
if(e->cap>0 && lev[from]<lev[e->to]) {
V f=dfs(e->to,to,min(cf,e->cap));
if(f>0) {
e->cap-=f;
E[e->to][e->reve].cap += f;
return f;
}
}
}
return 0;
}
V maxflow(int from, int to) {
V fl=0,tf;
while(1) {
bfs(from);
if(lev[to]<0) return fl;
ZERO(itr);
while((tf=dfs(from,to,numeric_limits<V>::max()))>0) fl+=tf;
}
}
};
MaxFlow_dinic<int> mf;
int N;
int U[303];
int D[303];
int L[303];
int R[303];
int A[303][303];
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1};
int vis[303][303];
int sta[303][303];
bool dfs(int y,int x) {
if(vis[y][x]) return false;
if(sta[y][x]) {
sta[y][x]=false;
return true;
}
sta[y][x]=true;
int cd=A[y][x];
for(int i=1;i<=N;i++) {
int ty=y+dy[cd]*i;
int tx=x+dx[cd]*i;
if(ty<0 || ty>=N || tx<0 || tx>=N) break;
//cout<<"go "<<y<<x<<" -> "<<ty<<tx<<endl;
if(dfs(ty,tx)) {
A[ty][tx]=cd;
if(sta[y][x]) {
sta[y][x]=false;
return true;
}
else {
return dfs(y,x);
}
}
}
sta[y][x]=false;
vis[y][x]=true;
if(cd==0) cout<<"L"<<(y+1);
if(cd==1) cout<<"R"<<(y+1);
if(cd==2) cout<<"U"<<(x+1);
if(cd==3) cout<<"D"<<(x+1);
cout<<endl;
//cout<<" "<<y<<x<<endl;
return false;
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) cin>>U[i];
FOR(i,N) cin>>D[i];
FOR(i,N) cin>>L[i];
FOR(i,N) cin>>R[i];
FOR(y,N) mf.add_edge(0,2+y,L[y]+R[y]);
FOR(x,N) mf.add_edge(0,302+x,U[x]+D[x]);
FOR(y,N) FOR(x,N) {
mf.add_edge(2+y,602+y*300+x,1);
mf.add_edge(302+x,602+y*300+x,1);
mf.add_edge(602+y*300+x,1,1);
}
if(mf.maxflow(0,1)!=N*N) return _P("NO\n");
FOR(y,N) FOR(x,N) {
FORR(e,mf.E[602+y*300+x]) if(e.cap==1 && e.to>=302 && e.to<602) A[y][x]=2; // UD
}
FOR(y,N) {
int tot=0;
FOR(x,N) if(A[y][x]==0) {
if(++tot>L[y]) A[y][x]=1;
}
}
FOR(x,N) {
int tot=0;
FOR(y,N) if(A[y][x]==2) {
if(++tot>U[x]) A[y][x]=3;
}
}
/*
FOR(y,N) {
FOR(x,N) cout<<"<>^v"[A[y][x]];
cout<<endl;
}
*/
FOR(y,N) FOR(x,N) dfs(y,x);
/*
FOR(y,N) {
FOR(x,N) cout<<"<>^v"[A[y][x]];
cout<<endl;
}
*/
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
Submission Info
Submission Time |
|
Task |
J - Neue Spiel |
User |
kmjp |
Language |
C++14 (GCC 5.4.1) |
Score |
2100 |
Code Size |
3575 Byte |
Status |
AC |
Exec Time |
303 ms |
Memory |
15796 KB |
Judge Result
Set Name |
sample |
dataset1 |
dataset2 |
Score / Max Score |
0 / 0 |
2000 / 2000 |
100 / 100 |
Status |
|
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt |
dataset1 |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt |
dataset2 |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
2 ms |
3456 KB |
01-02.txt |
AC |
2 ms |
3456 KB |
01-03.txt |
AC |
2 ms |
3456 KB |
01-04.txt |
AC |
2 ms |
3456 KB |
01-05.txt |
AC |
3 ms |
3584 KB |
01-06.txt |
AC |
4 ms |
3584 KB |
01-07.txt |
AC |
5 ms |
3840 KB |
01-08.txt |
AC |
5 ms |
3840 KB |
01-09.txt |
AC |
3 ms |
3584 KB |
01-10.txt |
AC |
5 ms |
3712 KB |
01-11.txt |
AC |
5 ms |
3840 KB |
01-12.txt |
AC |
5 ms |
3840 KB |
01-13.txt |
AC |
6 ms |
3840 KB |
01-14.txt |
AC |
2 ms |
3456 KB |
01-15.txt |
AC |
5 ms |
3712 KB |
01-16.txt |
AC |
6 ms |
3840 KB |
01-17.txt |
AC |
6 ms |
3840 KB |
01-18.txt |
AC |
6 ms |
3840 KB |
01-19.txt |
AC |
3 ms |
3584 KB |
01-20.txt |
AC |
6 ms |
3840 KB |
01-21.txt |
AC |
5 ms |
3840 KB |
01-22.txt |
AC |
3 ms |
3584 KB |
01-23.txt |
AC |
3 ms |
3584 KB |
01-24.txt |
AC |
6 ms |
3840 KB |
01-25.txt |
AC |
6 ms |
3840 KB |
01-26.txt |
AC |
2 ms |
3456 KB |
01-27.txt |
AC |
4 ms |
3584 KB |
01-28.txt |
AC |
6 ms |
3712 KB |
01-29.txt |
AC |
6 ms |
3840 KB |
01-30.txt |
AC |
6 ms |
3840 KB |
01-31.txt |
AC |
3 ms |
3584 KB |
01-32.txt |
AC |
6 ms |
3840 KB |
01-33.txt |
AC |
3 ms |
3584 KB |
01-34.txt |
AC |
6 ms |
3840 KB |
01-35.txt |
AC |
5 ms |
3712 KB |
01-36.txt |
AC |
5 ms |
3840 KB |
01-37.txt |
AC |
2 ms |
3584 KB |
01-38.txt |
AC |
5 ms |
3712 KB |
01-39.txt |
AC |
5 ms |
3840 KB |
01-40.txt |
AC |
5 ms |
3712 KB |
01-41.txt |
AC |
6 ms |
3840 KB |
01-42.txt |
AC |
5 ms |
3840 KB |
01-43.txt |
AC |
5 ms |
3712 KB |
01-44.txt |
AC |
5 ms |
3840 KB |
01-45.txt |
AC |
6 ms |
3712 KB |
01-46.txt |
AC |
6 ms |
3840 KB |
02-01.txt |
AC |
255 ms |
15796 KB |
02-02.txt |
AC |
255 ms |
15796 KB |
02-03.txt |
AC |
224 ms |
15668 KB |
02-04.txt |
AC |
234 ms |
15668 KB |
02-05.txt |
AC |
44 ms |
14132 KB |
02-06.txt |
AC |
43 ms |
14132 KB |
02-07.txt |
AC |
265 ms |
15668 KB |
02-08.txt |
AC |
303 ms |
15668 KB |
02-09.txt |
AC |
267 ms |
15668 KB |
02-10.txt |
AC |
218 ms |
15668 KB |
02-11.txt |
AC |
267 ms |
15668 KB |
02-12.txt |
AC |
219 ms |
15668 KB |
sample-01.txt |
AC |
2 ms |
3456 KB |
sample-02.txt |
AC |
2 ms |
3456 KB |