# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
241494 | marlicu | KOVANICE (COI15_kovanice) | C++14 | 139 ms | 17656 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
int n, m, v;
int pripada[MAXN];
vector <int> veze[MAXN];
bool ispisan[MAXN];
int vrsta[MAXN];
void init() {
for (int i = 1; i <= m; i++) {
pripada[i] = i;
}
}
void ispis() {
for (int i = 1; i <= m; i++) {
cout << pripada[i] << " ";
}
cout << '\n';
memset(ispisan, 0, sizeof(ispisan));
for (int i = 1; i <= m; i++) {
if (ispisan[i]) continue;
cout << i << " ";
int t = i;
while (veze[t].size()) {
cout << veze[t][0] << " ";
t = veze[t][0];
ispisan[t] = true;
}
cout << '\n';
ispisan[i] = true;
}
}
void konacan_ispis() {
int x;
for (int i = 1; i <= m; i++) {
x = pripada[i];
if (!vrsta[x]) cout << "?\n";
else cout << "K" << vrsta[x] << "\n";
}
}
void vaganje() {
string s;
cin >> s;
int a, b = 0;
char znak;
unsigned t = -1;
while (++t < s.size()) {
if (s[t] == '=' || s[t] == '<') {
znak = s[t];
a = b;
b = 0;
}
else {
b *= 10;
b += (s[t] - '0');
}
}
//cout << a << " " << znak << " " << b << '\n';
a = pripada[a];
b = pripada[b];
if (znak == '=') {
if (a < b) pripada[b] = a;
else pripada[a] = b;
}
else {
veze[a].push_back(b);
}
//ispis();
}
void odredivanje() {
vector <int> niz;
memset(ispisan, 0, sizeof(ispisan));
for (int i = 1; i <= m; i++) {
int t = pripada[i];
if (ispisan[t]) continue;
ispisan[t] = true;
niz.clear();
niz.push_back(t);
while (veze[t].size()) {
t = veze[t][0];
ispisan[t] = true;
niz.push_back(t);
}
/*
cout << niz.size() << " : ";
for (auto x : niz) {
cout << x << " ";
}
cout << '\n';
*/
if (niz.size() == n) {
for (int j = 0; j < n; j++) {
vrsta[niz[j]] = j + 1;
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m >> v;
init();
for (int i = 0; i < v; i++) {
vaganje();
}
odredivanje();
konacan_ispis();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |