답안 #893623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893623 2023-12-27T07:38:52 Z LeonaRaging Binaria (CCO23_day1problem1) C++14
0 / 25
6 ms 31368 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb emplace_back
#define pf emplace_front
#define fi first
#define se second
#define T pair<int,int>
#define all(val) val.begin(), val.end()
#define SZ(val) (int)val.size()
#define db(val) "[" #val " = " << (val) << "] "

const int maxn = 1e6 + 4;
const int N = 16;
const int mod = 1000003;
const int INF = 1e9;

void coding() {
    if (fopen("inputf.in", "r")) {
        freopen("inputf.in", "r", stdin);
        freopen("outputf.out", "w", stdout);
        freopen("log.out", "w", stderr);
    }
    if (fopen(".INP", "r")) {
        freopen(".INP", "r", stdin);
        freopen(".OUT", "w", stdout);
    }
}

int n, k, s[maxn], f[maxn], vis[maxn];
vector<pair<int,int>> adj[maxn];

void addedge(int u, int v, int w) {
//    clog << u << ' ' << v << ' ' << w << endl;
    adj[u].pb(v, w);
    adj[v].pb(u, w);
}

void dfs(int u) {
    vis[u] = 1;
    for (auto it : adj[u]) if (!vis[it.fi]) {
        int v, w; tie(v, w) = it;
        if (f[v] && (f[u] ^ w) != f[v]) {
            cout << 0;
            exit(0);
        }
        f[v] = f[u] ^ w;
        dfs(v);
    }
}

int mul(int a, int b) {
    return 1LL * a * b % mod;
}

int Pow(int a, int b) {
    if (b == 0) return 1;
    int t = Pow(a, b / 2);
    t = mul(t, t);
    if (b & 1) t = mul(t, a);
    return t;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    coding();
    cin >> n >> k;
    memset(f, -1, sizeof f);
    for (int i = 1; i <= n - k + 1; i++)
        cin >> s[i];
    for (int i = 1; i <= n - k; i++) {
        if (s[i + 1] - s[i] < -1 || s[i + 1] - s[i] > 1) return cout << 0, 0;
        if (s[i + 1] - s[i] == -1) f[i] = 1, f[i + k] = 0, addedge(i, i + k, 1);
        if (s[i + 1] - s[i] == 0) addedge(i, i + k, 0);
        if (s[i + 1] - s[i] == 1) f[i] = 0, f[i + k] = 1, addedge(i, i + k, 1);
    }
    int cnt = k;
    for (int i = 1; i <= k; i++) {
        int root = 0;
        for (int u = i; u <= n; u += k)
            if (f[u] != -1)
                root = u;
//        clog << i << ' ' << root << endl;
        if (!root) continue;
        dfs(root);
        if (f[i]) s[1]--;
        cnt--;
    }
    // C(cnt, s[1])
    int res = 1;
    for (int i = 1; i <= s[1]; i++)
        res = mul(res, Pow(i, mod - 2));
    for (int i = cnt - s[1] + 1; i <= cnt; i++)
        res = mul(res, i);
    cout << res;
}

Compilation message

Main.cpp: In function 'void coding()':
Main.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("inputf.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("outputf.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen("log.out", "w", stderr);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31324 KB Output is correct
2 Correct 6 ms 31368 KB Output is correct
3 Incorrect 6 ms 31340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31324 KB Output is correct
2 Correct 6 ms 31368 KB Output is correct
3 Incorrect 6 ms 31340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31324 KB Output is correct
2 Correct 6 ms 31368 KB Output is correct
3 Incorrect 6 ms 31340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31324 KB Output is correct
2 Correct 6 ms 31368 KB Output is correct
3 Incorrect 6 ms 31340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31324 KB Output is correct
2 Correct 6 ms 31368 KB Output is correct
3 Incorrect 6 ms 31340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31324 KB Output is correct
2 Correct 6 ms 31368 KB Output is correct
3 Incorrect 6 ms 31340 KB Output isn't correct
4 Halted 0 ms 0 KB -