답안 #1051968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051968 2024-08-10T10:50:14 Z otarius Alternating Current (BOI18_alternating) C++17
13 / 100
3000 ms 2392 KB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()

// #define int long long
// #define int unsigned long long

// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

void open_file(string filename) {
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}

// const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 1e5 + 25;

void solve() {
    srand(time(nullptr));
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    for (int i = 0; i < m; i++)
        cin >> a[i] >> b[i];
    for (int _ = 0; _ <= 10000000; _++) {
        int arr[m];
        for (int bt = 0; bt < m; bt++) {
            arr[bt] = rng() % 2;
        }int x[n + 5] = {}, y[n + 5] = {};
        for (int j = 0; j < m; j++) {
            if (arr[j]) {
                if (a[j] <= b[j]) {
                    x[a[j]]++; x[b[j] + 1]--;
                } else {
                    x[a[j]]++; x[1]++; x[b[j] + 1]--;
                }
            } else {
                if (a[j] <= b[j]) {
                    y[a[j]]++; y[b[j] + 1]--;
                } else {
                    y[a[j]]++; y[1]++; y[b[j] + 1]--;
                }
            }
        } bool f = 1;
        for (int j = 1; j <= n; j++) {
            x[j] += x[j - 1]; y[j] += y[j - 1];
            if (!x[j] || !y[j]) { f = 0; break; }
        }
        if (f) {
            for (int j = 0; j < m; j++) {
                cout << arr[j];
            } return;
        }
    } cout << "impossible";
}
int32_t main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

Compilation message

alternating.cpp: In function 'void open_file(std::string)':
alternating.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alternating.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 0 ms 348 KB Output is correct
8 Correct 743 ms 428 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 940 ms 428 KB Output is correct
11 Correct 785 ms 428 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1183 ms 344 KB Output is correct
14 Correct 0 ms 348 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 0 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 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1243 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 804 ms 428 KB Output is correct
30 Correct 667 ms 600 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 557 ms 428 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 286 ms 428 KB Output is correct
35 Correct 1655 ms 428 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1669 ms 424 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 0 ms 348 KB Output is correct
8 Correct 743 ms 428 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 940 ms 428 KB Output is correct
11 Correct 785 ms 428 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1183 ms 344 KB Output is correct
14 Correct 0 ms 348 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 0 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 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1243 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 804 ms 428 KB Output is correct
30 Correct 667 ms 600 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 557 ms 428 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 286 ms 428 KB Output is correct
35 Correct 1655 ms 428 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1669 ms 424 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Execution timed out 3095 ms 348 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 0 ms 348 KB Output is correct
8 Correct 743 ms 428 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 940 ms 428 KB Output is correct
11 Correct 785 ms 428 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1183 ms 344 KB Output is correct
14 Correct 0 ms 348 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 0 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 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1243 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 804 ms 428 KB Output is correct
30 Correct 667 ms 600 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 557 ms 428 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 286 ms 428 KB Output is correct
35 Correct 1655 ms 428 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1669 ms 424 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Execution timed out 3095 ms 348 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 2392 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Execution timed out 3095 ms 1628 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 0 ms 348 KB Output is correct
8 Correct 743 ms 428 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 940 ms 428 KB Output is correct
11 Correct 785 ms 428 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1183 ms 344 KB Output is correct
14 Correct 0 ms 348 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 0 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 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1243 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 804 ms 428 KB Output is correct
30 Correct 667 ms 600 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 557 ms 428 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 286 ms 428 KB Output is correct
35 Correct 1655 ms 428 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1669 ms 424 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Execution timed out 3095 ms 348 KB Time limit exceeded
44 Halted 0 ms 0 KB -