This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#pragma optimize "DostSeferoğlu"
#pragma GCC optimize("unroll-loops,Ofast")
#pragma GCC target("avx2,tune=native")
#define int long long
#define pii pair<int,int>
#define bg begin
#define vi vector<int>
#define endl '\n'
#define vvi vector<vi>
#define vp vector<pii>
#define sp << " " <<
#define ff first
#define ss second
#define brake {cout << "OK\n";return;}
#define debug(x) {cout << #x << ": "; for (auto it : x) cout << it << " ";cout << endl;}
#define FF(xxx,sss,yyy) for (int xxx=sss;xxx<=yyy;++xxx)
#define F(xx,yy) for (int xx=1;xx<=yy;++xx)
#define pb push_back
const int inf = 1e18;
const int MOD = 998244353;
const int N = 3e5+1;
vi dad(N);
int find(int x) {
if (x == dad[x]) return x;
return dad[x] = find(dad[x]);
}
void unite(int x,int y) {
dad[find(x)] = find(y);
}
void solve() {
int n,m,k;
cin >> n >> m >> k;
if (n == 2) {
set<int> betters,worses;
F(i,m) dad[i] = i;
dad[0]=0;
while (k--) {
string s;
cin >> s;
string n1,n2;
int seeneq = 0,seensm=0,seenbg=0;
for (auto c : s) {
if (c == '=') {
seeneq = 1;
continue;
}
if (c == '<') {
seensm = 1;
continue;
}
if (c == '>') {
seenbg = 1;
continue;
}
if (seeneq || seenbg || seensm) {
n2+=c;
}else n1+=c;
}
int x = stoi(n1);
int y = stoi(n2);
if (seeneq) {
unite(x,y);
}
else if (seensm){
betters.insert(x);
worses.insert(y);
}
else{
betters.insert(y);
worses.insert(x);
}
}
set<int> goods,bads;
for (auto it : betters) goods.insert(find(it));
for (auto it : worses) bads.insert(find(it));
for (int i=1;i<=m;i++) {
if (goods.count(find(i))) cout << "K1";
else if (bads.count(find(i))) cout << "K2";
else cout << "?";
if (i<m) cout << '\n';
}
}
else cout << -1 << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef Local
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
Compilation message (stderr)
kovanice.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
3 | #pragma optimize "DostSeferoğlu"
|
# | 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... |