답안 #1065914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065914 2024-08-19T13:04:21 Z EkinOnal Kocka (COCI18_kocka) C++17
70 / 70
104 ms 23308 KB
//#pragma GCC optimize("O3,unroll-loops,Ofast")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
 
#define MAX 200007
#define pb push_back
#define mp make_pair 
#define int long long
#define f first
#define s second
#define vi vector<int>
#define pii pair<int,int>
#define si set<int>
#define vpii vector<pair<int,int>> 
const int mod = 1e9+7;
const int INF = 1e18;
// myMap.begin()->first :  key
// myMap.begin()->second : value
 
int epow(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a;;b>>=1;}return ans;}
int gcd(int a,int b) {if(a<b)swap(a,b);while(b){int tmp=b;b=a%b;a=tmp;}return a;}
int mul(int a,int b){return ((a%mod)*(b%mod))%mod;}
int sum(int a,int b){return ((a%mod)+(b%mod))%mod;}
 
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

void solve(){
	int n; cin>>n;

	vi left(n),right(n),top(n),bottom(n);
//	for(int i=0;i<n;i++) cin>>left[i];
//	for(int i=0;i<n;i++) cin>>right[i];	
//	for(int i=0;i<n;i++) cin>>top[i];
//	for(int i=0;i<n;i++) cin>>bottom[i];

	vector<vi> rows(n+2),columns(n+2);	
	for(int i=0;i<n;i++){
		cin>>left[i];
		if(left[i]==-1) continue;
		rows[i+1].pb(left[i]+1);
		columns[left[i]+1].pb(i+1);
	}
	for(int i=0;i<n;i++){
		cin>>right[i];
		if(right[i]==-1) continue;
		rows[i+1].pb(n-right[i]);
		columns[n-right[i]].pb(i+1);
	}

	for(int i=0;i<n;i++){
		cin>>top[i];
		if(top[i]==-1) continue;
		columns[i+1].pb(top[i]+1);
		rows[top[i]+1].pb(i+1);
	}

	for(int i=0;i<n;i++){
		cin>>bottom[i];
		if(bottom[i]==-1) continue;
		columns[i+1].pb(n-bottom[i]);
		rows[n-bottom[i]].pb(i+1);
	}

	for(int i=1;i<=n;i++) sort(rows[i].begin(),rows[i].end());
	for(int i=1;i<=n;i++) sort(columns[i].begin(),columns[i].end());

//	for(int i=1;i<=n;i++){
//		for(auto u : rows[i]) cout<<u<<" ";
//			cout<<endl;
//	}


	for(int i=0;i<n;i++){
		if(left[i]==-1){
			if(rows[i+1].size()) {cout<<"NE\n";return;}
		}
		else if(rows[i+1][0]!=left[i]+1){cout<<"NE\n";return;}
	}
	for(int i=0;i<n;i++){
		if(right[i]==-1){
			if(rows[i+1].size()) {cout<<"NE\n";return;}
		}
		else if(rows[i+1][rows[i+1].size()-1]!=n-right[i]) {cout<<"NE\n";return;}
	}

	for(int i=0;i<n;i++){
		if(top[i]==-1){
			if(columns[i+1].size()) {cout<<"NE\n";return;}
		}
		else if(columns[i+1][0]!=top[i]+1) {cout<<"NE\n";return;}
	}
	for(int i=0;i<n;i++){
		if(bottom[i]==-1){
			if(columns[i+1].size()) {cout<<"NE\n";return;}
		}
		else if(columns[i+1][columns[i+1].size()-1]!=n-bottom[i]) {cout<<"NE\n";return;}
	}


	cout<<"DA\n";
	return;
}
 
int32_t main() {
//	freopen("hayfeast.in", "r", stdin);
//	freopen("hayfeast.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(0);   
 
    int t=1;
 //   cin >> t;
    while (t--) solve();
 
    return 0;
}
/*
3
-1 2 0
-1 0 1
2 2 1
0 0 1
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 18004 KB Output is correct
2 Correct 80 ms 23124 KB Output is correct
3 Correct 75 ms 23308 KB Output is correct
4 Correct 19 ms 9328 KB Output is correct
5 Correct 76 ms 23124 KB Output is correct
6 Correct 77 ms 23124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 22356 KB Output is correct
2 Correct 24 ms 9564 KB Output is correct
3 Correct 79 ms 23124 KB Output is correct
4 Correct 50 ms 20208 KB Output is correct
5 Correct 79 ms 23124 KB Output is correct
6 Correct 66 ms 22464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 18120 KB Output is correct
2 Correct 18 ms 9308 KB Output is correct
3 Correct 80 ms 23116 KB Output is correct
4 Correct 82 ms 23124 KB Output is correct
5 Correct 104 ms 23128 KB Output is correct
6 Correct 25 ms 9376 KB Output is correct