QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471356#895. ColorRong7WA 0ms3636kbC++144.0kb2024-07-10 20:44:132024-07-10 20:44:15

Judging History

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

  • [2024-07-10 20:44:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2024-07-10 20:44:13]
  • 提交

answer

// Not afraid to dark.

#include <bits/stdc++.h>
using namespace std;

//#define int long long

#define inline __inline__ __attribute__ ((always_inline))

namespace io {
	int pos;
	inline int read (int &p = pos){
		static int v; static char c;
		v = 1, c = getchar (), p = 0;
		while (! isdigit (c)){
			if (c == '-')
				v = - 1;
			c = getchar ();
		}
		while (isdigit (c)){
			p = (p << 1) + (p << 3) + (c - 48);
			c = getchar ();
		}
		return p *= v;
	}
	inline void write (int x){
		if (x < 0)
			putchar ('-'), x = - x;
		static int sta[65], top;
		top = 0;
		do {
			sta[++ top] = x % 10;
			x /= 10;
		} while (x);
		while (top)
			putchar (sta[top --] + 48);
	}
	inline char next_char (){
		static char c;
		c = getchar ();
		while (c == '\n' || c == ' ' || c == '\r')
			c = getchar ();
		return c;
	}
	inline void putss (const string s){
		for (int i = 0;i < (int) s.size ();++ i)
			putchar (s[i]);
	}
};

const int N = 2e2;

int n, m;
int col[N + 5][N + 5];
set < int > rst[N + 5];

namespace Dinic {
	const int P = N * 2 + 3, E = N * 10 + 5, inf = 0x3f3f3f3f;
	int firs[P + 5], nex[P + 5], to[P + 5], w[P + 5], tot = 1, s, t;
	inline void Clear (){
		s = t = 0;
		for (int i = 1;i <= P;++ i)
			firs[i] = 0;
		tot = 1;
	}
	inline void Add (int u, int v, int l){
		++ tot;
		nex[tot] = firs[u];
		firs[u] = tot;
		to[tot] = v;
		w[tot] = l;
		++ tot;
		nex[tot] = firs[v];
		firs[v] = tot;
		to[tot] = u;
		w[tot] = 0;
	}
	int dep[P + 5], cur[P + 5];
	queue < int > Q;
	inline bool Bfs (){
		for (int i = 1;i <= t;++ i){
			cur[i] = firs[i];
			dep[i] = inf;
		}
		dep[s] = 0;
		Q.push (s);
		while (! Q.empty ()){
			int u = Q.front ();
			Q.pop ();
			for (int e = firs[u], v;e;e = nex[e]){
				v = to[e];
				if (w[e] && dep[v] > dep[u] + 1){
					dep[v] = dep[u] + 1;
					Q.push (v);
				}
			}
		}
		return dep[t] != inf;
	}
	int Dfs (int u, int flow){
		if (u == t)
			return flow;
		int used = 0, rlow;
		for (int &e = cur[u], v;e;e = nex[e]){
			v = to[e];
			if (w[e] && dep[v] == dep[u] + 1){
				rlow = Dfs (v, min (w[e], flow - used));
				if (rlow){
					used += rlow;
					w[e] -= rlow;
					w[e ^ 1] += rlow;
					if (used == flow)
						break;
				}
			}
		}
		return used;
	}
	inline int FLOW (){
		static int Ansflow; Ansflow = 0;
		while (Bfs ())
			Ansflow += Dfs (s, inf);
		return Ansflow;
	}
} using namespace Dinic;

int db[N + 5], oe[N + 5];

signed main (){
	io::read (n), io::read (m);
	for (int i = 1;i <= m;++ i)
		for (int j = 1;j <= m;++ j)
			rst[i].insert (j);
	if ((m ^ 1) & 1)
		return io::putss ("No\n"), 0;
	for (int i = 1;i <= n;++ i)
		for (int j = i + 1;j <= n;++ j){
			io::read (col[i][j]);
			if (! rst[i].count (col[i][j]) || ! rst[j].count (col[i][j]))
				return io::putss ("No\n"), 0;
			rst[i].erase (col[i][j]);
			rst[j].erase (col[i][j]);
			++ db[col[i][j]];
		}
	for (int i = 1;i <= n;++ i)
		for (int x : rst[i])
			++ oe[x];
	for (int i = 1;i <= m;++ i)
		if (oe[i] + db[i] > m)
			return io::putss ("No\n"), 0;
	auto lid = [] (const int x){ return x; };
	auto rid = [] (const int x){ return x + m; };
	while (n < m){
		s = rid (n + 1) + 1, t = s + 1;
		for (int i = 1;i <= n;++ i)
			for (int x : rst[i])
				Add (lid (x), rid (i), 1);
		for (int i = 1;i <= m;++ i)
			Add (lid (i), rid (n + 1), m + 1 - ((db[i] + oe[i]) << 1)), Add (s, lid (i), 1);
		for (int i = 1;i <= n;++ i)
			Add (rid (i), t, 1);
		Add (rid (n + 1), t, m - n);
		if (FLOW () != m)
			return io::putss ("No\n"), 0;
		for (int i = 1;i <= n;++ i)
			for (int e = firs[rid (i)], v;e;e = nex[e]){
				v = to[e];
				if (w[e] == 1 && v != t)
					col[i][n + 1] = v;
			}
		++ n;
		for (int i = 1;i < n;++ i){
			rst[i].erase (col[i][n]);
			rst[n].erase (col[i][n]);
			++ db[col[i][n]], -- oe[col[i][n]];
		}
		for (int x : rst[n])
			++ oe[x];
		Clear ();
	}
	for (int i = 1;i <= n;++ i, putchar ('\n'))
		for (int j = i + 1;j <= n;++ j, putchar (' '))
			io::write (col[i][j]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3636kb

input:

3 5
1 2
4

output:

1 2 4 3 
4 3 5 
5 1 
2 


result:

wrong answer The first line should be "Yes" or "No"