답안 #1066747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1066747 2024-08-20T06:11:31 Z 12345678 Alternating Current (BOI18_alternating) C++17
13 / 100
3000 ms 3540 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5;

mt19937 rng(time(0));

int n, m, a[nx], b[nx], cur[nx], dp[nx], res[nx];
vector<pair<int, int>> v;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m;
    for (int i=0; i<m; i++) 
    {
        cin>>a[i]>>b[i];
        v.push_back({0, i});
    }
    for (int t=0; t<200000; t++)
    {
        for (int i=0; i<m; i++) v[i].first=rng(), res[i]=0;
        for (int i=1; i<=n; i++) cur[i]=dp[i]=0;
        sort(v.begin(), v.end());
        for (int i=0; i<m;i ++)
        {
            if (a[i]<=b[i]) for (int j=a[i]; j<=b[i]; j++) cur[j]++;
            else
            {
                for (int j=a[i]; j<=n; j++) cur[j]++;
                for (int j=1; j<=b[i]; j++) cur[j]++;
            }
        }
        for (int i=0; i<m; i++)
        {
            int idx=v[i].second;
            int mn=INT_MAX;
            if (a[idx]<=b[idx]) for (int j=a[idx]; j<=b[idx]; j++) mn=min(mn, cur[j]);
            else
            {
                for (int j=a[idx]; j<=n; j++) mn=min(mn, cur[j]);
                for (int j=1; j<=b[idx]; j++) mn=min(mn, cur[j]);
            }
            if (mn>=2)
            {
                res[idx]=1;
                if (a[idx]<=b[idx]) for (int j=a[idx]; j<=b[idx]; j++) cur[j]--, dp[j]++;
                else
                {
                    for (int j=a[idx]; j<=n; j++) cur[j]--, dp[j]++;
                    for (int j=1; j<=b[idx]; j++) cur[j]--, dp[j]++;
                }
            }
        }
        int f=0;
        for (int i=1;i <=n;i ++) if (dp[i]==0) f=1;
        if (!f)
        {
            for (int i=0; i<m;i ++) cout<<res[i];
            return 0;
        }
    }
    cout<<"impossible";
}

/*
10 5
1 5
6 7
5 1
7 2
2 4

10 5
1 4
2 5
4 7
6 10
8 1
*/
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 53 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 60 ms 460 KB Output is correct
11 Correct 54 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 74 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 78 ms 468 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 48 ms 348 KB Output is correct
30 Correct 39 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 33 ms 484 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 10 ms 348 KB Output is correct
35 Correct 117 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 104 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 53 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 60 ms 460 KB Output is correct
11 Correct 54 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 74 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 78 ms 468 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 48 ms 348 KB Output is correct
30 Correct 39 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 33 ms 484 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 10 ms 348 KB Output is correct
35 Correct 117 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 104 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Incorrect 854 ms 348 KB 'impossible' claimed, but there is a solution
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 53 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 60 ms 460 KB Output is correct
11 Correct 54 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 74 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 78 ms 468 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 48 ms 348 KB Output is correct
30 Correct 39 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 33 ms 484 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 10 ms 348 KB Output is correct
35 Correct 117 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 104 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Incorrect 854 ms 348 KB 'impossible' claimed, but there is a solution
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3024 ms 3540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 53 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 60 ms 460 KB Output is correct
11 Correct 54 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 74 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 78 ms 468 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 48 ms 348 KB Output is correct
30 Correct 39 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 33 ms 484 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 10 ms 348 KB Output is correct
35 Correct 117 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 104 ms 348 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 0 ms 468 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Incorrect 854 ms 348 KB 'impossible' claimed, but there is a solution
44 Halted 0 ms 0 KB -