Submission #646298

# Submission time Handle Problem Language Result Execution time Memory
646298 2022-09-29T12:35:48 Z mychecksedad Alternating Current (BOI18_alternating) C++17
0 / 100
19 ms 2004 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;



int n, m, ans[N];
pair<pair<int, int>, int> arr[N];
vector<bool> a, b;
void solve(){
    cin >> n >> m;
    for(int i = 0; i < m; ++i) cin >> arr[i].first.first >> arr[i].first.second;
    for(int i = 0; i < m; ++i) arr[i].second = i;
    sort(arr, arr+m);
    int l = 0, l1 = 0;
    a.resize(n + 1);
    b.resize(n + 1);
    for(int i = 0; i < m; ++i){
        if(arr[i].first.second > l){
            if(arr[i].first.first > l + 1){
                cout << "impossible";
                return;
            }
            ans[arr[i].second] = 1; 
            while(l < arr[i].first.second) a[l] = 1, l++;
            a[l] = 1;
        }
        else{
            if(arr[i].first.first > l1 + 1){
                cout << "impossible";
                return;
            }
            ans[arr[i].second] = 0;
            while(l1 < arr[i].first.second) b[l1] = 1, l1++;
            b[l1] = 1;
        }
    }
    bool ok = 1;
    for(int i = 1; i <= n; ++i) ok &= a[i] & b[i];
    if(ok) for(int i = 0; i < m; ++i) cout << ans[i];
    else cout << "impossible";
}





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

Compilation message

alternating.cpp: In function 'int main()':
alternating.cpp:60:16: warning: unused variable 'aa' [-Wunused-variable]
   60 |     int T = 1, aa;
      |                ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2004 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 7 ms 852 KB Output is correct
4 Incorrect 8 ms 860 KB 'impossible' claimed, but there is a solution
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -