답안 #646301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646301 2022-09-29T12:40:49 Z mychecksedad Alternating Current (BOI18_alternating) C++17
0 / 100
25 ms 1944 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;

bool comp(pair<pair<int, int>, int> &a, pair<pair<int, int>, int> &b){
    if(a.first.first == b.first.first) return a.first.second > b.first.second;
    return a.first.first < b.first.first;
}

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, comp);
    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:63:16: warning: unused variable 'aa' [-Wunused-variable]
   63 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1944 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 9 ms 912 KB Output is correct
4 Correct 16 ms 1108 KB Output is correct
5 Incorrect 25 ms 1420 KB 'impossible' claimed, but there is a solution
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB 'impossible' claimed, but there is a solution
4 Halted 0 ms 0 KB -