Submission #891076

# Submission time Handle Problem Language Result Execution time Memory
891076 2023-12-22T07:22:17 Z vjudge1 Jail (JOI22_jail) C++17
5 / 100
2750 ms 11856 KB
/*
 
author : abushbandit
contest : ---
 
*/
 
#include "bits/stdc++.h"
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
 
using namespace std;
 
#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ff first
#define ss second
#define pb push_back
#define rep(i,s,f) for(int i = s;i < f;i++)
 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
#pragma GCC optimize("Ofast,no-stack-protector,fast-math",3)
 
template <class type1>
	using ordered_multiset = tree <type1, null_type, less_equal <type1>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
 
const ll INF = 1e18;
const ll MOD7 = 1e9 + 7;
const ll MOD9 = 998244353;
const ld PI = acos(-1.0);
const int N = 120000 + 2;
 
template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}
 
template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
    
}
 
int binpow (int a, int n) {
	int res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		a *= a;
		n >>= 1;
	}
	return res;
}
 
void start_file(string file){
	freopen((file + ".in").c_str(),"r",stdin);
	freopen((file + ".out").c_str(),"w",stdout);
}

void solve() {
	
	int n;
    cin >> n;
    vector<vector<int>> g(n);
    bool bamboo = 1;
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        if(!(a == i && b == i + 1)){
            bamboo = 0;
        }
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }
//    if(bamboo) {
        vector<bool> used(n, 0);
        bool flag = 1;
        deque<pair<int, int>> l, r;
        int m;
        cin >> m;
        while (m--) {
            int s, t;
            cin >> s >> t;
            s--, t--;
            if (t > s) {
                r.push_back({t, s});
            } else {
                l.push_back({t, s});
            }
            used[s] = 1;
        }
        sort(all(l)), sort(all(r));
        while (!l.empty()) {
            int s = l.front().second, t = l.front().first;
            l.pop_front();
            used[s] = 0;
            while (s >= t) {
                if (used[s]) {
                    flag = 0;
                    break;
                }
                s--;
            }
            used[t] = 1;
        }
        while (!r.empty()) {
            int s = r.back().second, t = r.back().first;
            r.pop_back();
            used[s] = 0;
            while (s <= t) {
                if (used[s]) {
                    flag = 0;
                    break;
                }
                s++;
            }
            used[t] = 1;
        }
        if(flag){
        	cout << "Yes\n";
		} else{
			cout << "No\n";
		}
//    } else {
//        
//    }

	
}

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

Compilation message

jail.cpp: In function 'void solve()':
jail.cpp:84:10: warning: variable 'bamboo' set but not used [-Wunused-but-set-variable]
   84 |     bool bamboo = 1;
      |          ^~~~~~
jail.cpp: In function 'void start_file(std::string)':
jail.cpp:75:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |  freopen((file + ".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
jail.cpp:76:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  freopen((file + ".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 9 ms 348 KB Output is correct
5 Correct 20 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 28 ms 712 KB Output is correct
10 Correct 68 ms 8272 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 25 ms 1360 KB Output is correct
13 Correct 41 ms 9796 KB Output is correct
14 Correct 39 ms 9704 KB Output is correct
15 Correct 39 ms 9752 KB Output is correct
16 Correct 53 ms 11856 KB Output is correct
17 Correct 2750 ms 9996 KB Output is correct
18 Correct 59 ms 11604 KB Output is correct
19 Correct 898 ms 10068 KB Output is correct
20 Correct 911 ms 9952 KB Output is correct
21 Correct 34 ms 10076 KB Output is correct
22 Correct 49 ms 10068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 6 ms 464 KB Output is correct
6 Incorrect 1 ms 600 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 9 ms 348 KB Output is correct
5 Correct 20 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 28 ms 712 KB Output is correct
10 Correct 68 ms 8272 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 25 ms 1360 KB Output is correct
13 Correct 41 ms 9796 KB Output is correct
14 Correct 39 ms 9704 KB Output is correct
15 Correct 39 ms 9752 KB Output is correct
16 Correct 53 ms 11856 KB Output is correct
17 Correct 2750 ms 9996 KB Output is correct
18 Correct 59 ms 11604 KB Output is correct
19 Correct 898 ms 10068 KB Output is correct
20 Correct 911 ms 9952 KB Output is correct
21 Correct 34 ms 10076 KB Output is correct
22 Correct 49 ms 10068 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -