QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#235129 | #6705. Median | bronze_RE | WA | 2ms | 3748kb | C++20 | 2.5kb | 2023-11-02 14:41:36 | 2023-11-02 14:41:36 |
Judging History
answer
#include <bits/stdc++.h>
#define endl "\n"
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0), cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef priority_queue<PII, vector<PII>, greater<PII>> Qu;
inline int read() { char c = getchar(); int tot = 1; while ((c < '0' || c>'9') && c != '-') c = getchar(); if (c == '-') { tot = -1; c = getchar(); }int sum = 0; while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); }return sum * tot; }
inline void write(ll x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); }
const int N = 1e2 + 9;
const int INF = 0x3f3f3f3f;
const int M = 1e9 + 9;
const int Mod = 998244253;
vector<int>don[N], node[N];
int in[N], In[N];
int Sub[N];
int Pre[N];
void solve()
{
int n ,m ;cin >> n >> m;
for(int i = 1;i <= n;i++) {
in[i] = In[i] = 0, Sub[i] = Pre[i] = 0;
node[i].clear();
don[i].clear();
}
for(int i = 1;i <= m;i++){
int u ,v; cin >> u >> v;
node[v].push_back(u);
in[u] ++;
In[v] ++;
don[u].push_back(v);
}
int mid = (n + 1) / 2;
queue<int> q;
for(int i = 1;i <= n;i++){
Pre[i] = 1;
if(in[i] == 0) q.push(i);
}
while(q.size()){
int u = q.front() ; q.pop();
for(int i = 0; i < node[u].size() ;i++){
int v = node[u][i];
Pre[v] += Pre[u]; // 当前点有几个肯定比他小的
if( -- in[v] == 0){
q.push(v);
}
}
}
for(int i = 1;i <= n;i++){
if(in[i]){
for(int i = 1;i <= n;i++) cout << 0 ;
cout << endl;
return ;
}
if(In[i] == 0) q.push(i);
Sub[i] = 1;
}
while(q.size()){
int u = q.front() ; q.pop();
for(int i = 0; i < don[u].size() ;i++){
int v = don[u][i];
Sub[v] += Sub[u]; // 当前点有几个明确比他大的;
if( -- In[v] == 0){
q.push(v);
}
}
}
for(int i = 1;i <= n;i++){
// cout << Pre[i] << " " << Sub[i] << endl;
if(mid >= Pre[i] && mid <= n - Sub[i] + 1) cout << 1 ;
else cout << 0 ;
}
cout << endl;
return ;
}
int main()
{
IOS;
int ___ = 1; cin >> ___;
for (int i = 1; i <= ___; i++)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 2ms
memory: 3748kb
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 111111111111111 000000000000000 00000 01000 1111111 0000000000000 111000101 111111111 000000001010000 010111111 000000000 0000000000000 1111111111111 000000000000000 00000101001 000000000000000 11111111111 00000000000 11111 00000000000 11101110111 00000 1111...
result:
wrong answer 2nd lines differ - expected: '01001000111', found: '00000000111'