답안 #445350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445350 2021-07-17T14:45:24 Z grt Tenis (COCI20_tenis) C++17
80 / 110
63 ms 3652 KB
#include <bits/stdc++.h>
#define ST first
#define ND second
#define PB push_back

using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 100 * 1000 + 10, INF = 1e9;
int n;
int p[3][nax];
int inv[nax][3];
bool visited[nax];
int ans[nax];
int res[3];
int cnt[10][3];

void match(int a, int b) {
	if(a == b) return;
	pi best = {INF, INF};
	for(int i = 0; i < 3; ++i) {
		best = min(best, {min(inv[a][i], inv[b][i]), max(inv[a][i], inv[b][i])});
	}
	for(int i = 0; i < 3; ++i) {
		if(make_pair(min(inv[a][i], inv[b][i]), max(inv[a][i], inv[b][i])) == best) {
			if(inv[a][i] < inv[b][i]) ans[a]++;
			else ans[b]++;
			res[i]++;
			return;
		}
	}
}


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int j = 0; j < 3; ++j) {
		for(int i = 1; i <= n; ++i) {
			cin >> p[j][i];
			inv[p[j][i]][j] = i;
		}
	}
	for(int i = 1; i <= n; ++i) {
		for(int mask = 1; mask < (1 << 3); ++mask) {
			pi best = {INF, -1};
			for(int j = 0; j < 3; ++j) {
				if(mask & (1 << j)) {
					best = min(best, {inv[i][j], j});
				}
			}
			cnt[mask][best.ND]++;
		}
	}
	int done = 0;
	for(int i = 1; i <= n; ++i) {
		vector<int>g;
		for(int j1 = 0; j1 < 3; ++j1) {
			if(!visited[p[j1][i]]) {
				for(int mask = 1; mask < (1 << 3); ++mask) {
					pi best = {INF, -1};
					for(int j = 0; j < 3; ++j) {
						if(mask & (1 << j)) {
							best = min(best, {inv[p[j1][i]][j], j});
						}
					}
					cnt[mask][best.ND]--;
				}
				done++;
				g.PB(j1);
			}
			visited[p[j1][i]] = true;
		}
		for(int j1 : g) for(int j2 : g) {
			if(j1 < j2) match(p[j1][i], p[j2][i]);
		}
		for(int j : g) {
			int mask = 0;
			for(int j2 = 0; j2 < 3; ++j2) {
				if(p[j][i] == p[j2][i]) mask += (1 << j2);
			}
			ans[p[j][i]] += n - done;
			for(int j2 = 0; j2 < 3; ++j2) {
				res[j2] += cnt[mask][j2];
			}
		}
	}
	for(int i = 0; i < 3; ++i) cout << res[i] << " ";
	cout << "\n";
	for(int i = 1; i <= n; ++i) cout << ans[i] << " ";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 24 ms 1700 KB Output is correct
6 Correct 40 ms 2344 KB Output is correct
7 Correct 50 ms 3060 KB Output is correct
8 Correct 63 ms 3652 KB Output is correct
9 Partially correct 61 ms 3652 KB Partially correct
10 Partially correct 59 ms 3632 KB Partially correct