QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#593562 | #6705. Median | PonyHex | WA | 3ms | 3776kb | C++20 | 3.9kb | 2024-09-27 14:38:34 | 2024-09-27 14:38:34 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define ll long long
//#define double long double
#define lc u<<1
#define rc u<<1|1
#define X first
#define Y second
#define endl "\n"
#define int long long
const int N = 2e3 + 50;
const int M = 5e5 + 5;
const ll maxm = 1e18 + 5;
const ll mod = 998244353;
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
//random_shuffle(id + 1, id + n + 1);
ll ksm(ll a, ll b);
ll gcd(ll a, ll b);
template<class T>inline void read(T& x) {
x = 0;
char c = getchar();
while (!isdigit(c))c = getchar();
while (isdigit(c))x = x * 10 + (c & 15), c = getchar();
}
void write(ll x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
return;
}
bool f[N];
vector<pair<ll, ll> >op;
vector<vector<ll> >e(N);
int din[N];
void solve()
{
//这个赛时就有思路,感觉是拓扑,正走一遍反走一遍,维护每个元素一定比他大的个数,一定比他小的个数
//但是,怎么说,,先,怎么没思路
//两遍拓扑即可,应该
//感觉就是一个dfs,回来写,不对,这样被办法准确找到一定大于的元素,看看题再说
//哦,不是,这纯水题啊,我还在想分叉怎么处理,结果根本不分叉,其实就直直一条线
//建好图,入度为0 的点入队就完了,水的不行,裸的拓扑吧
//我是罪人,m的边1到n^2不一定为连通图,所以判环应该要利用出现的节点的数量,不应该使用n
//唉,还是缺少经验,写的太少,细节不到位
set<ll>s;
ll n, m; cin >> n >> m;
for (int i = 1; i <= n; i++)f[i] = 1;
for (int i = 1; i <= m; i++) {
ll u, v; cin >> u >> v;
s.insert(u); s.insert(v);
op.push_back({ u,v });
}
//走一遍顺势
for (auto p = op.begin(); p != op.end(); p++) {
ll u = p->X, v = p->Y;
e[u].push_back(v);
din[v]++;
}
ll idx = 0;
queue<ll>q;
/*
for (int i = 1; i <= n; i++) {
if (din[i] == 0)q.push(i);
}*/
for (auto p = s.begin(); p != s.end(); p++) {
if (din[*p] == 0)q.push(*p);
}
while (q.size()) {
queue<ll>mid;
ll pr = q.size();
while (q.size()) {
ll u = q.front(); q.pop();
if (idx > n / 2)f[u] = 0;
for (auto p = e[u].begin(); p != e[u].end(); p++) {
ll v = *p; din[v]--;
if (din[v] == 0) {
mid.push(v);
}
}
}
idx += pr;
//cout << idx << endl;
while (mid.size()) {
q.push(mid.front());
mid.pop();
}
}
for (int i = 1; i <= n; i++) {
e[i].clear(); din[i] = 0;
}
if (idx != s.size()) {
for (int i = 1; i <= n; i++)cout << 0;
cout << endl;
op.clear(); return;
}
//感觉有点多余,给出的应该是不分叉的线性关系
//走一遍逆势
for (auto p = op.begin(); p != op.end(); p++) {
ll v = p->X, u = p->Y;
e[u].push_back(v);
din[v]++;
}
idx = 0;
for (auto p = s.begin(); p != s.end(); p++) {
if (din[*p] == 0)q.push(*p);
}
while (q.size()) {
queue<ll>mid;
ll pr = q.size();
while (q.size()) {
ll u = q.front(); q.pop();
if (idx > n / 2)f[u] = 0;
for (auto p = e[u].begin(); p != e[u].end(); p++) {
ll v = *p; din[v]--;
if (din[v] == 0) {
mid.push(v);
}
}
}
idx += pr;
while (mid.size()) {
q.push(mid.front());
mid.pop();
}
}
for (int i = 1; i <= n; i++) {
e[i].clear(); din[i] = 0;
}
for (int i = 1; i <= n; i++)cout << f[i];
cout << endl;
op.clear();
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
//read(T);
while (T--)
solve();
return 0;
}
/*PonyHex*/
ll ksm(ll a, ll b) {
ll base = a;
ll ans = 1;
while (b) {
if (b & 1)ans *= base % mod;
ans %= mod;
base *= base; base %= mod;
b >>= 1;
}
return ans % mod;
}
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
2 5 4 1 2 3 2 2 4 2 5 3 2 1 1 2 3
output:
01000 000
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3776kb
input:
66 13 2 9 13 7 11 11 19 9 1 8 1 5 1 2 8 4 2 2 1 5 2 6 3 3 11 3 2 4 6 6 10 9 8 3 5 1 7 5 8 3 9 4 9 6 7 3 1 2 3 11 6 9 4 1 6 5 2 1 5 4 6 8 4 15 15 10 6 15 8 7 6 11 1 5 2 3 4 11 13 4 6 10 12 10 13 1 6 15 2 5 12 13 14 5 3 15 86 14 12 8 1 14 9 8 15 5 10 1 9 11 2 6 2 7 10 10 13 14 5 4 13 5 8 4 10 13 9 6 9...
output:
1111111111111 00000000111 111 11111111111 110000111001101 001001000000000 00100 01100 1101101 1000000000000 101000101 111101011 000001001000000 010011111 001100000 0000001001100 1100001010110 001000010000000 00000111001 001000000000100 11111011100 00000000001 11111 00000000110 11000100100 00000 1111...
result:
wrong answer 2nd lines differ - expected: '01001000111', found: '00000000111'