답안 #1113942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113942 2024-11-17T21:40:53 Z mariaclara Alternating Current (BOI18_alternating) C++17
0 / 100
3000 ms 2888 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair 
#define pb push_back
#define fr first 
#define sc second 

int n, m, group[MAXN];
int main() {

    cin >> n >> m;
    vector<pair<pii,int>> v(m);

    for(int i = 0; i < m; i++) {
        cin >> v[i].fr.fr >> v[i].fr.sc;
        if(v[i].fr.fr > v[i].fr.sc) v[i].fr.sc += n;
        v[i].sc = i;
    }

    sort(all(v));
    auto [A,B] = v[0].fr;
    bool possible = 0;

    for(int i = 1; i < sz(v); i++) {
        // i é o primeiro elemento do 2° grupo
        group[v[i].sc] = 1;
        auto [C,D] = v[i].fr;

        int B_ = B;
        for(int j = i+1; j < sz(v); j++) {
            if(B_ <= D and B_ - A < n - 1) {
                if(v[j].fr.fr <= B_+1) B_ = max(B_, v[j].fr.sc);
                group[v[j].sc] = 0;
            }
            else {
                if(v[j].fr.fr <= D+1) D = max(D, v[j].fr.sc);
                group[v[j].sc] = 1;
            }
        }
        
        if(B_ - A >= n-1 and D - C >= n-1) {
            possible = 1;
            break;
        }

        group[v[i].sc] = 0;
        if(v[i].fr.fr <= B+1) B = max(B, v[i].fr.sc);
    }

    if(!possible) {
        cout << "impossible\n";
        return 0;
    }

    for(int i = 0; i < m; i++) cout << group[i];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 348 KB 'impossible' claimed, but there is a solution
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 348 KB 'impossible' claimed, but there is a solution
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 348 KB 'impossible' claimed, but there is a solution
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 2888 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1293 ms 1604 KB Output is correct
4 Correct 22 ms 1616 KB Output is correct
5 Correct 46 ms 2888 KB Output is correct
6 Execution timed out 3058 ms 2632 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 348 KB 'impossible' claimed, but there is a solution
6 Halted 0 ms 0 KB -