Submission #536868

# Submission time Handle Problem Language Result Execution time Memory
536868 2022-03-14T06:26:54 Z akhan42 Tug of War (BOI15_tug) C++17
23 / 100
21 ms 6488 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define F first
#define S second
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forbn(i, b, n) for(int i = b; i < n; ++i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define lc v << 1
#define rc (v << 1) + 1

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef complex<double> cd;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

template <class T> inline void mineq(T &a, T b) { a = min(a, b); }
template <class T> inline void maxeq(T &a, T b) { a = max(a, b); }


const int MX = 30 * 1000 + 5;
int l[MX], r[MX], s[MX];
set<int> sp2id[2 * MX];


void solve() {
	int n, k;
	cin >> n >> k;

	forn(i, 2 * n) {
		cin >> l[i] >> r[i] >> s[i];
		l[i]--; r[i]--;
		sp2id[l[i]].insert(i);
		sp2id[r[i] + n].insert(i);
	}

	set<ii> q;

	forn(sp, 2 * n) {
		q.insert({sz(sp2id[sp]), sp});
	}

	while(!q.empty() && q.begin()->F < 2) {
		int ss = q.begin()->F, sp = q.begin()->S;
		if(ss == 0) {
			cout << "NO\n";
			return;
		}
		int i = *sp2id[sp].begin();
		int sp2 = sp == l[i] ? r[i] + n : l[i];

		q.erase({sz(sp2id[sp]), sp});
		q.erase({sz(sp2id[sp2]), sp2});

		sp2id[sp].erase(i);
		sp2id[sp2].erase(i);

		q.insert({sz(sp2id[sp2]), sp2});
	}

	cout << "YES\n";
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

//	freopen("triangles.in", "r", stdin);
//	freopen("triangles.out", "w", stdout);

	int t = 1;
//	cin >> t;
	while(t--) {
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 6444 KB Output is correct
2 Correct 14 ms 6356 KB Output is correct
3 Correct 13 ms 6396 KB Output is correct
4 Correct 13 ms 6356 KB Output is correct
5 Correct 15 ms 6364 KB Output is correct
6 Correct 16 ms 6392 KB Output is correct
7 Correct 15 ms 6356 KB Output is correct
8 Correct 16 ms 6356 KB Output is correct
9 Correct 17 ms 6416 KB Output is correct
10 Correct 15 ms 6356 KB Output is correct
11 Correct 12 ms 6356 KB Output is correct
12 Correct 14 ms 6424 KB Output is correct
13 Correct 18 ms 6440 KB Output is correct
14 Correct 15 ms 6360 KB Output is correct
15 Correct 20 ms 6308 KB Output is correct
16 Correct 15 ms 6488 KB Output is correct
17 Correct 15 ms 6440 KB Output is correct
18 Correct 16 ms 6356 KB Output is correct
19 Correct 13 ms 6416 KB Output is correct
20 Correct 13 ms 6412 KB Output is correct
21 Correct 14 ms 6348 KB Output is correct
22 Correct 21 ms 6316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3156 KB Output isn't correct
2 Halted 0 ms 0 KB -