이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
const int mod=998244353, maxn=1e5+5;
int n, a[10][maxn], ki, ka, atas, bwh, pmin[maxn], pmax[maxn], cnt[maxn], paski[maxn];
bool ans=true;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n;
for(int i=1; i<=4; i++) {
for(int j=1; j<=n; j++) cin >> a[i][j];
}
for(int i=0; i<=n; i++) pmin[i]=mod, pmax[i]=-1;
for(int i=1; i<=n; i++) {
ki=a[1][i], ka=a[2][i];
if((ki==-1)^(ka==-1)) ans=false;
if((ki==-1)&&(ka==-1)) continue;
if(ki+ka+1<=n) {
ki++, ka=n-ka;
pmin[ki]=min(pmin[ki], i);
pmin[ka+1]=min(pmin[ka+1], mod);
pmax[ki]=max(pmax[ki], i);
pmax[ka+1]=max(pmax[ka+1], -1);
cnt[ki]++, cnt[ka+1]--, paski[ki]++;
} else ans=false;
}
for(int i=1; i<=n; i++) {
cnt[i]+=cnt[i-1];
if(cnt[i]==0||cnt[i]==paski[i]) continue;
pmin[i]=min(pmin[i], pmin[i-1]);
pmax[i]=max(pmax[i], pmax[i-1]);
}
for(int i=1; i<=n; i++) {
atas=a[3][i], bwh=a[4][i];
if((atas==-1)^(bwh==-1)) ans=false;
if(atas==-1&&bwh==-1) {
if(!(pmin[i]==mod&&pmax[i]==-1)) ans=false;
else continue;
}
if(!((atas==pmin[i]-1)&&(n-pmax[i]==bwh))) ans=false;
}
cout << ((ans)?"DA":"NE") << '\n';
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |