Submission #559694

# Submission time Handle Problem Language Result Execution time Memory
559694 2022-05-10T12:13:43 Z jcelin KOVANICE (COI15_kovanice) C++14
100 / 100
821 ms 112460 KB
#include <bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define matrix vector<vi>
#define matrixLL vector<vLL>
#define vs vector<string>
#define vui vector<ui>
#define msi multiset<int>
#define mss multiset<string>
#define si set<int>
#define ss set<string>
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int dxx[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dyy[] = {0, 0, -1, 1, -1, 1, -1, 1};
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ld pi = 3.14159265;
const int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 7;
const int inf = mod;
const ll INF = 1e18;
const ll zero = ll(0);
const int logo = 20;
const int off = 1 << logo;
const int trsz = off << 1;


vii edges[3];

map<char, int> ab = {
	{'<', 1},
	{'=', 0}
};

void conv(string s){
	char p = '.';
	string fir, las, a = "";
	for(int i=0; i<s.size(); i++){
		if(s[i] == '=' or s[i] == '<' ) p = s[i], fir = a, a = "";
		else a = a + s[i];
	}
	las = a;
	edges[ab[p]].PB(MP(stoi(fir), stoi(las)));
}

vi color;
vi g[MAXN], g2[MAXN], adj[MAXN];
int dub[MAXN], dub2[MAXN], ans[MAXN];

void dfs(int u, int c){
	color[u] = c;
	for(auto x: g2[u]) if(!color[x]) dfs(x, c);
}

map<ii, bool> was;


void calc(int u){
	dub[u] = 1;
	for(auto x: g[u]){
		if(!dub[x]) calc(x); 
		dub[u] = max(dub[u], dub[x] + 1);
	}
}

void calc2(int u){
	dub2[u] = 1;
	for(auto x: adj[u]){
		if(!dub2[x]) calc2(x); 
		dub2[u] = max(dub2[u], dub2[x] + 1);
	}	
}



void solve(){
	int n, m, k;
	cin >> n >> m >> k;
	color.resize(m + 1);
	string s;
	for(int i=0; i<k; i++) cin >> s, conv(s);
	
	for(auto &x: edges[0]){
		int a = x.X, b = x.Y;
		g2[a].PB(b);
		g2[b].PB(a);
	}
	
	for(int i=1; i<=m; i++) if(!color[i]) dfs(i, i);
	
	//for(int i=1; i<=m; i++) cout << color[i] << " ";
	
	for(auto x: edges[1]){
		int a = color[x.X], b = color[x.Y];
		if(was[MP(a, b)]) continue;
		was[MP(a, b)] = 1;
		g[a].PB(b);
		adj[b].PB(a);
	}
	

	for(int i=1; i<=m; i++) if(!ans[color[i]]){
		calc(color[i]), calc2(color[i]);
		if(dub[color[i]] + dub2[color[i]] == n + 1) ans[color[i]] = dub2[color[i]];
		else ans[color[i]] = -1;
	}
	
	
	//cout << "\n";
	for(int i=1; i<=m; i++){
		if(ans[color[i]] != -1) cout << "K" << ans[color[i]] << "\n";
		else cout << "?\n";
	}
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--)solve();
	return 0;
}






Compilation message

kovanice.cpp: In function 'void conv(std::string)':
kovanice.cpp:62:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for(int i=0; i<s.size(); i++){
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 35 ms 70860 KB Output is correct
2 Correct 36 ms 70896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 201 ms 83552 KB Output is correct
2 Correct 180 ms 85072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 72072 KB Output is correct
2 Correct 82 ms 73696 KB Output is correct
3 Correct 96 ms 74884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 563 ms 102732 KB Output is correct
2 Correct 646 ms 106752 KB Output is correct
3 Correct 567 ms 106408 KB Output is correct
4 Correct 808 ms 112460 KB Output is correct
5 Correct 821 ms 111484 KB Output is correct