답안 #966159

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966159 2024-04-19T12:55:23 Z blackslex Alternating Heights (CCO22_day1problem1) C++17
0 / 25
252 ms 3408 KB
#include<bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;

int n, k, q, x, y;

int main() {
    scanf("%d %d %d", &n, &k, &q);
    vector<int> a(n + 5), dp(n + 5); iota(dp.begin(), dp.end(), 0);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int idx = 1, idx2 = 1;
    while (idx <= n) {
        auto ck = [&] (int l, int r) {
            vector<vector<int>> v(n + 5, vector<int>());
            for (int i = l; i <= r; i++) {
                if (i != l && (i & 1) == (l & 1)) v[a[i]].emplace_back(a[i - 1]);
                if (i != r && (i & 1) == (l & 1)) v[a[i]].emplace_back(a[i + 1]);
            }
            vector<int> f(n + 5), f2(n + 5);
            function<int(int, int)> cyc = [&] (int cur, int par) {
                if (f[cur]) return f2[cur] = 1; f[cur] = 1;
                for (auto &e: v[cur]) if (cyc(e, cur)) return (f2[cur] ? 0 : f2[cur] = 1);
                return 0;
            };
            cyc(a[l], 0);
            for (int i = l; i <= r; i++) if (f2[a[i]]) return 1;
            return 0;
        };
        while (idx2 < n) {
            if (!ck(idx, idx2 + 1)) idx2++;
            else break;
        }
        dp[idx] = idx2;
        idx++; idx2 = max(idx2, idx);
    }
    while (q--) scanf("%d %d", &x, &y), printf("%s\n", dp[x] >= y ? "YES" : "NO");
}

Compilation message

Main.cpp: In lambda function:
Main.cpp:22:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   22 |                 if (f[cur]) return f2[cur] = 1; f[cur] = 1;
      |                 ^~
Main.cpp:22:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   22 |                 if (f[cur]) return f2[cur] = 1; f[cur] = 1;
      |                                                 ^
Main.cpp: In function 'int main()':
Main.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d %d", &n, &k, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:11:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
      |                                  ~~~~~^~~~~~~~~~~~~
Main.cpp:37:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     while (q--) scanf("%d %d", &x, &y), printf("%s\n", dp[x] >= y ? "YES" : "NO");
      |                 ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 252 ms 3408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 218 ms 3408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 190 ms 564 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 252 ms 3408 KB Output isn't correct
2 Halted 0 ms 0 KB -