Submission #851777

# Submission time Handle Problem Language Result Execution time Memory
851777 2023-09-20T15:05:05 Z TimDee Colors (RMI18_colors) C++17
47 / 100
3000 ms 15220 KB
//  Esti <3

//\
     šťastia pre nás :)
//   you're already the best
//             _
//   ^ ^      //
// >(O_O)<___//
//   \ __ __  \
//    \\ \\ \\\\
 
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3","unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
 
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")

using ll = long long;
#define int long long
#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second 
#define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e18;
const int mod = 998244353;
 
// \
\
:smiling_face_with_3_hearts: :smiling_face_with_3_hearts:  :smiling_face_with_3_hearts:  
 
//vidime sa veľmi skoro, moje slnko
	
const int N = 2e5+5;

int n,m;
int a[N], b[N];
bitset<N> vis;
bitset<N> ok;
vector<int> adj[N];

int dfs(int u, int x) {
	if (a[u] < x) return 0;
	if (a[u]==x) return 1;
	if (vis[u]) return 0;
	if (ok[u]) return 0;
	vis[u]=1;
	for(auto&v:adj[u]) {
		dfs(v,x);
		if (a[v]==x) a[u]=x;
	}
	return a[u]==x;
}

int can(int s, int x) {
	vis.reset();
	return dfs(s,x);
}

void solve() {

	cin>>n>>m;
	forn(i,n) cin>>a[i];
	forn(i,n) cin>>b[i];
	vector<pi> e(m);
	forn(i,m) cin>>e[i].f>>e[i].s;

	forn(i,n) {
		if (a[i]<b[i]) {
			cout<<"0\n"; return;
		}
	}

	forn(i,n) adj[i].clear();
	ok.reset();
	forn(i,m) {
		int u=e[i].f, v=e[i].s; --u, --v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	vector<pi> v;
	forn(i,n) v.pb({b[i],i});
	sort(rall(v));

	for(auto&x:v) {
		int z = can(x.s, x.f);
		//cout<<x.f<<' '<<x.s<<' '<<z<<'\n';
		if (!z) {
			cout<<"0\n"; return;
		}
		ok[x.s]=1;
	}
	cout<<"1\n";

}

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

Compilation message

colors.cpp:3:1: warning: multi-line comment [-Wcomment]
    3 | //\
      | ^
colors.cpp:9:1: warning: multi-line comment [-Wcomment]
    9 | //   \ __ __  \
      | ^
colors.cpp:36:1: warning: multi-line comment [-Wcomment]
   36 | // \
      | ^
# Verdict Execution time Memory Grader output
1 Correct 66 ms 6832 KB Output is correct
2 Correct 22 ms 7260 KB Output is correct
3 Correct 4 ms 7160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 6996 KB Output is correct
2 Correct 21 ms 7256 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 6996 KB Output is correct
2 Correct 21 ms 7256 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
4 Correct 124 ms 9752 KB Output is correct
5 Execution timed out 3048 ms 15220 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 66 ms 6832 KB Output is correct
2 Correct 22 ms 7260 KB Output is correct
3 Correct 4 ms 7160 KB Output is correct
4 Correct 71 ms 6996 KB Output is correct
5 Correct 21 ms 7256 KB Output is correct
6 Correct 3 ms 6748 KB Output is correct
7 Correct 66 ms 8224 KB Output is correct
8 Correct 24 ms 7204 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 6748 KB Output is correct
2 Execution timed out 3027 ms 14740 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 6748 KB Output is correct
2 Correct 8 ms 7268 KB Output is correct
3 Correct 4 ms 7000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 6832 KB Output is correct
2 Correct 22 ms 7260 KB Output is correct
3 Correct 4 ms 7160 KB Output is correct
4 Correct 45 ms 6748 KB Output is correct
5 Correct 71 ms 6996 KB Output is correct
6 Correct 21 ms 7256 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 124 ms 9752 KB Output is correct
9 Execution timed out 3048 ms 15220 KB Time limit exceeded
10 Halted 0 ms 0 KB -