이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, k, q, arr[3010], dp[3010], x, y, vs[3010], idx, l, r, mid;
bool cnt;
pair<int, int> temp;
vector<int> g[3010];
int cyclic(int u)
{
vs[u] = 1;
for (int v : g[u])
if (vs[v] == 1 || !vs[v] && cyclic(v)) return 1;
vs[u] = 2;
return 0;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k >> q;
for(int i=1; i<=n; i++) {
cin >> arr[i];
}
for(int i=1; i<=n; i++) {
l=i; r=n;
while(l<r) {
mid = (l+r)>>1;
for(int j=1; j<=n; j++) {
g[j].clear();
}
for(int j=i+1; j<=n; j++) {
if(j%2 == 0) {
g[arr[j-1]].push_back(arr[j]);
} else {
g[arr[j]].push_back(arr[j-1]);
}
}
for (int j = i; cnt && j > mid; --j) if (!vs[arr[j]] && cyclic(arr[j])) cnt = 0;
if(cnt) {
r = mid;
} else {
l = mid+1;
}
}
dp[i] = l;
}
while(q--) {
cin >> x >> y;
if(x == y || dp[x] <= y) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int cyclic(int)':
Main.cpp:14:34: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
14 | if (vs[v] == 1 || !vs[v] && cyclic(v)) return 1;
| ~~~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |