text
stringlengths
49
983k
#include <iostream> using namespace std; typedef long long ll; int main() { ll N; while (cin >> N, N) { ll S = 0; for (ll i = 1; i * i <= N; ++i) { if (N % i == 0 && i != N) { S += i; if (i != N / i && N / i != N) S += N / i; } } if (N == S) cout << "perfect number\n"; else if (N > S) cout << "deficient number\n"; else cout << "abundant number\n"; } return 0; }
#include<algorithm> #include<iostream> #include<string> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> using namespace std; int main(){ int i; int l,n,s; while(cin>>n&&n){ s=n>1; l=(int)sqrt(n)+1; for(i=2;i<l;i++){ if(n%i==0){ s+=i; if(i*i!=n) s+=n/i; } } if(0){ }else if(s<n){ cout<<"deficient number"<<endl; }else if(s>n){ cout<<"abundant number"<<endl; }else{ cout<<"perfect number"<<endl; } } return 0; }
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) #define repb(i,a,b) for(int i=a;i>=b;i--) #define all(a) a.begin(),a.end() #define o(a) cout<<a<<endl #define int long long #define fi first #define se second using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; int calc(int n){ int res = 0; for(int i = 1; i*i <= n; i++){ if(n % i == 0){ res += i; if(i*i != n) res += n / i; } } return res - n; } signed main(){ int n; while(cin >> n, n){ int sum = calc(n); //o(sum); if(sum == n) cout << "perfect number" << endl; if(sum < n) cout << "deficient number" << endl; if(sum > n) cout << "abundant number" << endl; } }
#include<iostream> #include<iomanip> #include<algorithm> #include<bitset> #include<cctype> #include<climits> #include<cmath> #include<cstdio> #include<cstring> #include<deque> #include<list> #include<map> #include<set> #include<stack> #include<string> #include<sstream> #include<queue> #include<vector> using namespace std; int main(void) { while (true) { int n; cin >> n; if (n == 0)break; int s = 0; s -= n; for (int i = 1; i <= sqrt(n); i++) { if (n%i == 0) { s += n / i; if (n != 1 && i != n / i) s += i; } } //cout << s << endl; if (n == s) cout << "perfect number" << endl; else if (n > s) cout << "deficient number" << endl; else cout << "abundant number" << endl; } return 0; }
#include<stdio.h> #include<iostream> #include<fstream> #include<stack> #include<math.h> using namespace std; int main(){ int n; while (cin >> n, n){ if (n < 2){ cout << "deficient number" << endl; continue; } int s = 1; for (int i = 2; i <= sqrt(n); i++){ if (n%i == 0 && i == sqrt(n) && n / sqrt(n) == sqrt(n)){ s += i; } else if (n%i == 0){ s += i; s += n / i; } } if (n == s)cout << "perfect number" << endl; if (n > s)cout << "deficient number" << endl; if (n < s)cout << "abundant number" << endl; } return 0; }
#include <iostream> using namespace std; int main(){ int n; while(cin >> n && n){ int sum = 0; for(int i=1;i*i<=n;i++){ if(n%i==0){ sum += i + n/i; if(i*i == n) sum -= i; } } if(sum == 2*n) cout << "perfect number" << endl; else if(sum < 2*n) cout << "deficient number" << endl; else cout << "abundant number" << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int,int> pii; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define all(a) (a).begin(),(a).end() #define pb push_back #define INF 999999999 vector<ll> divisor(ll n){ vector<ll> ret; for(int i=1;i<=sqrt(n);i++){ if(n%i==0){ ret.pb(i); if(i!=n/i)ret.pb(n/i); } } // sort(all(ret)); return ret; } int main(){ int n; while(cin>>n&&n){ vector<ll> res = divisor(n); int sum = 0; rep(i,res.size()){ sum+=res[i]; } sum-=n; if(sum==n)cout<<"perfect number"<<endl; if(n>sum)cout<<"deficient number"<<endl; if(n<sum)cout<<"abundant number"<<endl; } }
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int main(){ while(1){ int n; cin >> n; if(n == 0) break; int sum = 0; for(int i = 1; i * i <= n; i++){ if(n % i == 0 && n != 1){ sum += i; if(n/i != n)sum += n / i; if(i * i == n)sum -= i; } } if(sum < n) cout << "deficient number" << endl; else if(sum > n) cout << "abundant number" << endl; else if(sum == n) cout << "perfect number" << endl; } return 0; }
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; int main(void){ int n; while(cin >> n && n){ int s = 0; for(int i = 1; i*i <= n; i++){ if(n%i) continue; s += i; if(i*i < n) s += n/i; } s -= n; if(n == s){ cout << "perfect number" << endl; }else if(n > s){ cout << "deficient number" << endl; }else{ cout << "abundant number" << endl; } } }
#include <iostream> using namespace std; int main(void) { long long N, sum; while (1) { cin >> N; if (N == 0) break; sum = 1; for (long long i = 2; i*i <= N; i++) { if (N % i == 0) { long long tmp = N / i; sum += i; if (i != tmp) { sum += tmp; } } if (sum > N) { cout << "abundant number" << endl; break; } } if (N == 1 || sum < N) { cout << "deficient number" << endl; } else if (sum == N) { cout << "perfect number" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf("%d", &n) && n){ int s = 0; for (int i = 1; i * i <= n; i++){ if (n % i == 0){ if (i != n / i) s += n / i; s += i; } } if (2 * n > s) printf("deficient number\n"); if (2 * n < s) printf("abundant number\n"); if (2 * n == s) printf("perfect number\n"); } return (0); }
#include <iostream> #include <algorithm> using namespace std; int main(){ int n; while(cin >> n,n){ int ret = -n; for(int i = 1 ; i*i < n ; i++ ){ if(n%i == 0){ ret += i + n/i; if(i == n/i)ret-=i; } } if( n == ret)cout << "perfect number" << endl; else if(n > ret)cout <<"deficient number"<< endl; else cout << "abundant number" << endl; } return 0; }
#include<iostream> using namespace std; int main(void){ int n,i; long long sum; while(1){ cin >> n; if(n==0)break; sum=0; for(int i=1;i*i<n;i++){ if(n%i==0){ sum+=i; if(i!=1)sum+=n/i; } } if(n==sum)cout << "perfect number" << endl; else if(n<sum)cout << "abundant number" << endl; else cout << "deficient number" << endl; } return 0; }
#include <iostream> using namespace std; typedef long long ll; int main(){ int N; ll S; while(1){ cin >> N; if(N==0) break; S=0; for(int i=1;i*i<N;i++) if(N%i==0) S+=(i+N/i); if(N!=1) S-=N; if(N==S) cout << "perfect number" << endl; else if(N>S) cout << "deficient number" << endl; else cout << "abundant number" << endl; } return 0; }
#include<iostream> #include<cmath> #include<vector> using namespace std; int main(){ int n; while(1){ cin >> n; if(!n)break; vector<int> d; int r = (int)sqrt(n); for(int i=2;i<=r;i++){ if( !(n%i) ){ d.push_back(i); if(i!=n/i)d.push_back(n/i); } } int sum = 0; if(n!=1){ sum += 1; for(int i=0;i<(int)d.size();i++){ sum += d[i]; } } if(sum<n)cout << "deficient number" << endl; else if(sum>n)cout << "abundant number" << endl; else cout << "perfect number" << endl; } }
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) { break; } int sum = 0; if (n != 1) { sum++; } for (int i = 2; i*i <= n; i++) { if (n % i == 0) { sum += i; sum += n/i; if (i*i == n) { sum -= i; } } } if (sum == n && n != 1) { cout << "perfect number" << endl; } else if (n < sum) { cout << "abundant number" << endl; } else { cout << "deficient number" << endl; } } return 0; }
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <stack> #include <algorithm> using namespace std; #define rep(i,j) REP((i), 0, (j)) #define REP(i,j,k) for(int i=(j);(i)<(k);++i) #define between(a,x,b) ((a)<=(x)&&(x)<=(b)) #define F first #define S second #define INF 1 << 30 int main(){ int N; while(scanf("%d", &N) && N){ int r = sqrt(N); int sum = 0; for(int i = 1; i <= r; i++){ if(i == N) continue; if(N%i == 0){ sum += i; if(N/i == N || N/i == i) continue; sum += N/i; } } if(sum == N) puts("perfect number"); else if(sum < N) puts("deficient number"); else if(sum > N) puts("abundant number"); } return 0; }
#include<iostream> using namespace std; int main(void) { int n; int sum; char str[][100] = { {"deficient number\0"}, {"abundant number\0"}, {"perfect number\0"} }; while(cin >> n && n){ sum = 1; for(int i = 2; i*i < n; i++){ if(!(n%i)) sum += i + n / i; } if(n!=1){ if(sum == n){ cout << str[2] << endl; } if(sum > n){ cout << str[1] << endl; } if(sum < n){ cout << str[0] << endl; } } else { cout << str[0] << endl; } } return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<tuple> using namespace std; int main() { int n, u, v, m; cin >> n >> u >> v >> m; bool draw = true; int val; vector<pair<int,int>> usagi(1000001), neko(1000001); vector<int> usanum,nekonum; for(int i=0 ; i<n ; i++){ for(int j=0; j<n ; j++){ cin >> val; usagi[val] = pair<int,int>(i,j); usanum.push_back(val); } } for(int i=0 ; i<n ; i++){ for(int j=0; j<n ; j++){ cin >> val; neko[val] = pair<int,int>(i,j); nekonum.push_back(val); } } sort(usanum.begin(),usanum.end()); sort(nekonum.begin(),nekonum.end()); vector<int> usagi_dp(2*n+2,0), neko_dp(2*n+2,0); int hoge,fuga; int uwin=0,nwin=0; vector<bool> uc(2*n+2,false),nc(2*n+2,false); for(int i=0 ; i< m ;i++){ cin >> val; if(binary_search(usanum.begin(), usanum.end(),val)){ tie(hoge,fuga) = usagi[val]; usagi_dp[hoge]++; if(!uc[hoge] && usagi_dp[hoge]>=n){ uc[hoge]=true; uwin++; } usagi_dp[n+fuga]++; if(!uc[n+fuga] && usagi_dp[n+fuga]>=n){ uc[n+fuga]=true; uwin++; } if(hoge==fuga){ usagi_dp[2*n]++; if(!uc[2*n] && usagi_dp[2*n]>=n){ uc[2*n]=true; uwin++; } } if(hoge == n-fuga -1){ usagi_dp[2*n+1]++; if(!uc[2*n+1] && usagi_dp[2*n+1]>=n){ uc[2*n+1]=true; uwin++; } } } //uwin = (usagi_dp[hoge]>=u) || (usagi_dp[n+fuga]>=u) || (usagi_dp[2*n]>=u) || (usagi_dp[2*n+1]>=u); if(binary_search(nekonum.begin(), nekonum.end(),val)){ tie(hoge,fuga) = neko[val]; neko_dp[hoge]++; neko_dp[n+fuga]++; if(!nc[hoge] && neko_dp[hoge]>=n){ nc[hoge]=true; nwin++; } if(!nc[n+fuga] && neko_dp[n+fuga]>=n){ nc[n+fuga]=true; nwin++; } if(hoge==fuga){ neko_dp[2*n]++; if(!nc[2*n] && neko_dp[2*n]>=n){ nc[2*n]=true; nwin++; } } if(hoge == n-fuga -1){ neko_dp[2*n+1]++; if(!nc[2*n+1] && neko_dp[2*n+1]>=n){ nc[2*n+1]=true; nwin++; } } } //nwin = (neko_dp[hoge]>=v) || (neko_dp[n+fuga]>=v) || (neko_dp[2*n]>=v) || (neko_dp[2*n+1]>=v); if(n==1){ uwin = min(1,uwin); nwin = min(1,nwin); } if( uwin >= u ){ if(nwin >= v)break; cout << "USAGI" << endl; draw=false; break; }else if(nwin >= v){ cout << "NEKO" << endl; draw=false; break; } } if(draw) cout << "DRAW" << endl; return 0; }
/* 05:55 - 06:20 first leg 06:20 - 6:50 finished */ #include<iostream> #include<algorithm> #include<vector> #include<cassert> #include<climits> #include<unordered_map> #include<unordered_set> #define REP(i,s,n) for(int i=s;i<n;i++) #define rep(i,n) REP(i,0,n) #define IINF (INT_MAX) #define MAX 501 using namespace std; typedef pair<int,int> ii; int n,u,v,m,card; int G[MAX][MAX][2]; bool used[MAX][MAX][2]; bool row[MAX][2],column[MAX][2],diag[2][2]; int dx[] = {+1,0,+1,-1}; int dy[] = {0,+1,+1,+1}; bool check(int type,int player,int p){ int x,y; if(type == 0)x = 0, y = p; // テ・ツ渉ウ else if(type == 1)x = p, y = 0; // テ、ツクツ? else if(type == 2)x = y = 0; //テ、ツコツ暗ヲツδウテ」ツ?ョテ」ツ?ッテ」ツつ凝」ツ?凝ヲツ鳴愿」ツつ?」ツつ津」ツ?づ」ツ?づ」ツ?? else if(type == 3)x = n-1, y = 0; rep(i,n){ assert( 0 <= x && x < n && 0 <= y && y < n ); if(!used[y][x][player])return false; x = x + dx[type]; y = y + dy[type]; } return true; } inline void increment(int& a,int& b,int player){ if(player == 0)a++; else b++; } int main(){ unordered_map<int,ii> place[2]; cin >> n >> u >> v >> m; rep(i,2)rep(y,n)rep(x,n){ cin >> G[y][x][i]; place[i][G[y][x][i]] = ii(x,y); } int limit_USAGI = u, limit_NEKO = v; int score_USAGI = 0,score_NEKO = 0; string win = "$"; rep(i,m){ cin >> card; if(win[0] != '$')continue; rep(player,2){ if(place[player].find(card) != place[player].end()){ ii p = place[player][card]; used[p.second][p.first][player] = true; if(!row[p.second][player]){ if(check(0,player,p.second)){ row[p.second][player] = true; increment(score_USAGI,score_NEKO,player); } } if(!column[p.first][player]){ if(check(1,player,p.first)){ column[p.first][player] = true; increment(score_USAGI,score_NEKO,player); } } if(p.first == p.second && !diag[0][player]){ if(check(2,player,0)){ diag[0][player] = true; increment(score_USAGI,score_NEKO,player); } } if(p.second == n-p.first-1 && !diag[1][player]){ if(check(3,player,0)){ diag[1][player] = true; increment(score_USAGI,score_NEKO,player); } } } } if(n == 1)score_USAGI = min(score_USAGI,1), score_NEKO = min(score_NEKO,1); if(score_USAGI >= limit_USAGI && score_NEKO >= limit_NEKO){ win = "DRAW"; //limit_USAGI++, limit_NEKO++; } else if( score_USAGI >= limit_USAGI ){ win = "USAGI"; } else if( score_NEKO >= limit_NEKO ){ win = "NEKO"; } } if(win[0] == '$')cout << "DRAW" << endl; else cout << win << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using P = pair<int, int>; int main() { int n, u, v, m; cin >> n >> u >> v >> m; map<int, P> mpu, mpv; REP(i, n) REP(j, n) { int k; cin >> k; mpu[k] = {i, j}; } REP(i, n) REP(j, n) { int k; cin >> k; mpv[k] = {i, j}; } int ans = 0; vector<int> cu(2 * n + 2, 0), cv(2 * n + 2, 0); REP(i, m) { int q; cin >> q; if (n == 1) { if (mpu.find(q) != end(mpu)) { P p = mpu[q]; cu[0]++; } if (mpv.find(q) != end(mpv)) { P p = mpv[q]; cv[0]++; } } else { if (mpu.find(q) != end(mpu)) { P p = mpu[q]; cu[p.first]++; cu[n + p.second]++; if (p.first == p.second) cu[2 * n]++; if (p.first == n - 1 - p.second) cu[2 * n + 1]++; } if (mpv.find(q) != end(mpv)) { P p = mpv[q]; cv[p.first]++; cv[n + p.second]++; if (p.first == p.second) cv[2 * n]++; if (p.first == n - 1 - p.second) cv[2 * n + 1]++; } } int nu = 0, nv = 0; REP(j, 2 * n + 2) { if (cu[j] == n) nu++; if (cv[j] == n) nv++; } if (nu >= u) ans += 1; if (nv >= v) ans += 2; if (ans == 0) continue; if (ans == 1) { cout << "USAGI" << endl; return 0; } if (ans == 2) { cout << "NEKO" << endl; return 0; } if (ans == 3) { cout << "DRAW" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
//#include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <bitset> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <stack> #include <queue> #include <deque> #include <cstring> #include <string> #include <utility> #include <array> #include <complex> #include <valarray> #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <chrono> #include <random> #include <numeric> #include<memory> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ull; //typedef unsigned __int128 HASH; typedef pair<int,int> pii; typedef pair<ll, ll> pll; typedef pair<ull, ull> pullull; typedef pair<ll,int> plli; typedef pair<double,int> pdi; typedef pair<long double, int> pdbi; typedef pair<int,pii> pipii; typedef pair<ll,pll> plpll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; typedef vector<vector<int>> mat; #define rep(i,n) for (int i=0;i<(n);i++) #define rep2(i,a,b) for (int i=(a);i<(b);i++) #define rrep(i,n) for (int i=(n);i>0;i--) #define rrep2(i,a,b) for (int i=(a);i>b;i--) #define pb push_back #define fi first #define se second #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() const ll hmod1 = 999999937; const ll hmod2 = 1000000000 + 9; const int INF = 1<<30; const ll INFLL = 1LL<<62; const long double EPS = 1e-12; const ll mod = 1000000000 + 7; //const ll mod = 998244353; const int dx4[4] = {1, 0, -1, 0}; const int dy4[4] = {0, 1, 0, -1}; const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1}; const long double pi = 3.141592653589793; #define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod #define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false //debug #define DEBUG #define DUMPOUT cerr #ifdef DEBUG #define dump(...) DUMPOUT<<#__VA_ARGS__<<" :["<<__FUNCTION__<<":"<<__LINE__<<"]"<<endl; DUMPOUT<<" "; dump_func(__VA_ARGS__) #else #define dump(...) #endif void dump_func() {DUMPOUT << endl;}; template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) DUMPOUT << " "; else DUMPOUT << ", "; dump_func(std::move(tail)...); } //ostream template<typename T> ostream& operator << (ostream& os, vector<T>& vec) { os << "["; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "]"; return os; } template<typename T, typename U> ostream& operator << (ostream& os, pair<T, U>& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } template<typename T, typename U> ostream& operator << (ostream& os, map<T, U>& map_var) { os << "["; for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if(itr != map_var.end()) os << ", "; itr--; } os << "]"; return os; } template<typename T> ostream& operator << (ostream& os, set<T>& set_var) { os << "["; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if(itr != set_var.end()) os << ", "; itr--; } os << "]"; return os; } int n, u, v, m; int c1[500][500], c2[500][500]; int cnty1[500], cntx1[500], cnty2[500], cntx2[500]; map<int, int> yy1, x1, y2, x2; int Usagi, Neko; int ex1, ex2, ex3, ex4; signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> u >> v >> m; rep(i, n)rep(j, n) { cin >> c1[i][j]; yy1[c1[i][j]] = i; x1[c1[i][j]] = j; } rep(i, n)rep(j, n) { cin >> c2[i][j]; y2[c2[i][j]] = i; x2[c2[i][j]] = j; } rep(i, m) { int num; cin >> num; if (yy1.find(num) != yy1.end()) { cnty1[yy1[num]]++; cntx1[x1[num]]++; if (n == 1) { Usagi++; } else { if (yy1[num] == x1[num]) { ex1++; Usagi += (ex1 == n ? 1 : 0); } if (yy1[num] + x1[num] == n-1) { ex2++; Usagi += (ex2 == n ? 1 : 0); } Usagi += (cnty1[yy1[num]] == n ? 1 : 0); Usagi += (cntx1[x1[num]] == n ? 1 : 0); } } if (y2.find(num) != y2.end()) { cnty2[y2[num]]++; cntx2[x2[num]]++; if (n == 1) { Neko++; } else { if (y2[num] == x2[num]) { ex3++; Neko += (ex3 == n ? 1 : 0); } if (y2[num] + x2[num] == n-1) { ex4++; Neko += (ex4 == n ? 1 : 0); } Neko += (cnty2[y2[num]] == n ? 1 : 0); Neko += (cntx2[x2[num]] == n ? 1 : 0); } } if (Usagi >= u && Neko >= v) { cout << "DRAW" << endl; return 0; } if (Usagi >= u) { cout << "USAGI" << endl; return 0; } if (Neko >= v) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)n;i++) int paper_u[500][500],paper_n[500][500]; int n2c_u[1000000],n2c_n[1000000],n2r_u[1000000],n2r_n[1000000]; int cscore_u[500],cscore_n[500],rscore_u[500],rscore_n[500]; int d1score_u=0,d1score_n=0,d2score_u=0,d2score_n=0; int sum_u=0,sum_n=0; int main(){ int n,u,v,m; cin >> n >> u >> v >> m; rep(i,1000000){ n2c_u[i]=-1; n2c_n[i]=-1; n2r_u[i]=-1; n2r_n[i]=-1; } rep(i,n)rep(j,n){ cin >> paper_u[i][j]; paper_u[i][j]--; n2c_u[paper_u[i][j]] = i; n2r_u[paper_u[i][j]] = j; } rep(i,n)rep(j,n){ cin>>paper_n[i][j]; paper_n[i][j]--; n2c_n[paper_n[i][j]] = i; n2r_n[paper_n[i][j]] = j; } int flag=0; rep(i,m){ if(flag)break; int card; cin >> card; card--; if (n2c_u[card]>=0){ cscore_u[n2c_u[card]]++; if (cscore_u[n2c_u[card]]==n)sum_u++; if (n2c_u[card]==n2r_u[card]&&n>=2){ d1score_u++; if (d1score_u==n)sum_u++; } if (n2c_u[card]+n2r_u[card]==n-1&&n>=2){ d2score_u++; if (d2score_u==n)sum_u++; } } if (n2c_n[card]>=0){ cscore_n[n2c_n[card]]++; if (cscore_n[n2c_n[card]]==n)sum_n++; if (n2c_n[card]==n2r_n[card]&&n>=2){ d1score_n++; if (d1score_n==n)sum_n++; } if (n2c_n[card]+n2r_n[card]==n-1&&n>=2){ d2score_n++; if (d2score_n==n)sum_n++; } } if (n2r_u[card]>=0&&n>=2){ rscore_u[n2r_u[card]]++; if (rscore_u[n2r_u[card]]==n)sum_u++; } if (n2r_n[card]>=0&&n>=2){ rscore_n[n2r_n[card]]++; if (rscore_n[n2r_n[card]]==n)sum_n++; } if (sum_u>=u){ if (sum_n>=v){ cout << "DRAW" << endl; flag = 1; } else { cout << "USAGI" << endl; flag = 1; } } else if (sum_n>=v){ cout << "NEKO" << endl; flag = 1; } } if (!flag)cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define LOG(...) fprintf(stderr,__VA_ARGS__) //#define LOG(...) #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define REP(i,n) for(int i=0;i<(int)(n);++i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define SZ(a) ((int)(a).size()) #define BIT(x, i) (((x) >> (i)) & 1) typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; int main() { int n, usagi, neko, cards; cin >> n >> usagi >> neko >> cards; map<int, pii> usagi_p; map<int, pii> neko_p; REP(i, n) REP(j, n) { int c; cin >> c; usagi_p[c] = {i, j}; } REP(i, n) REP(j, n) { int c; cin >> c; neko_p[c] = {i, j}; } int sum = (n+1) * (n/2); if (n % 2 == 1) { sum += (n+1) / 2; } vi usagi_v(n, sum); vi usagi_h(n, sum); vi usagi_s(2, sum); vi neko_v(n, sum); vi neko_h(n, sum); vi neko_s(2, sum); bool finished = false; REP(i, cards) { int card; cin >> card; if (finished) continue; if (EXIST(usagi_p, card)) { pii p = usagi_p[card]; int x = p.first, y = p.second; usagi_v[x] -= y+1; usagi_h[y] -= x+1; if (x == y) usagi_s[0] -= x+1; if (y == n-1-x) usagi_s[1] -= y+1; } if (EXIST(neko_p, card)) { pii p = neko_p[card]; int x = p.first, y = p.second; neko_v[x] -= y+1; neko_h[y] -= x+1; if (x == y) neko_s[0] -= x+1; if (y == n-1-x) neko_s[1] -= y+1; } int usagi_bingo = 0, neko_bingo = 0; REP(i, n) { if (usagi_v[i] == 0) usagi_bingo++; if (usagi_h[i] == 0) usagi_bingo++; if (neko_v[i] == 0) neko_bingo++; if (neko_h[i] == 0) neko_bingo++; } if (usagi_s[0] == 0) usagi_bingo++; if (usagi_s[1] == 0) usagi_bingo++; if (neko_s[0] == 0) neko_bingo++; if (neko_s[1] == 0) neko_bingo++; if (n == 1) { usagi_bingo = min(1, usagi_bingo); neko_bingo = min(1, neko_bingo); } bool usagi_won = usagi_bingo >= usagi; bool neko_won = neko_bingo >= neko; if (usagi_won && neko_won) { cout << "DRAW" << endl; finished = true; } else if (usagi_won) { cout << "USAGI" << endl; finished = true; } else if (neko_won) { cout << "NEKO" << endl; finished = true; } } if (!finished) { cout << "DRAW" << endl; } }
#pragma GCC optimize ("O3") #pragma GCC target ("tune=native") #pragma GCC target ("avx") #include <bits/stdc++.h> // 汎用マクロ #define ALL_OF(x) (x).begin(), (x).end() #define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++) #define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++) #define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--) #define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0; } template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0; } #define INF 0x7FFFFFFF #define LINF 0x7FFFFFFFFFFFFFFFLL #define Yes(q) (q ? "Yes" : "No") #define YES(q) (q ? "YES" : "NO") #define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl #define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl // gcc拡張マクロ #define gcd __gcd #define popcount __builtin_popcount #define popcountll __builtin_popcountll // エイリアス using ll = long long; using ull = unsigned long long; using ld = long double; using namespace std; // モジュール // 処理内容 int main() { ll n, u, v, m; cin >> n >> u >> v >> m; vector<vector<ll>> udrawn(n, vector<ll>(n)), vdrawn(n, vector<ll>(n)); REP(i, n) REP(j, n) cin >> udrawn[i][j]; REP(i, n) REP(j, n) cin >> vdrawn[i][j]; vector<ll> cards(m); REP(i, m) cin >> cards[i]; if (n == 1) { ll udr = udrawn[0][0]; ll vdr = vdrawn[0][0]; ll upt = 0, vpt = 0; REP(i, m) { if (cards[i] == udr) upt++; if (cards[i] == vdr) vpt++; if (upt >= u && vpt >= v) { std::cout << "DRAW" << endl; return 0; } else if (vpt >= v) { std::cout << "NEKO" << endl; return 0; } else if (upt >= u) { std::cout << "USAGI" << endl; return 0; } } std::cout << "DRAW" << endl; return 0; } vector<ll> udic(1000001, -1), vdic(1000001, -1); REP(i, n) REP(j, n) { udic[udrawn[i][j]] = i*n+j; vdic[vdrawn[i][j]] = i*n+j; } vector<ll> uhitr(n, 0), uhitc(n, 0); ll uhitd0 = 0, uhitd1 = 0; vector<ll> vhitr(n, 0), vhitc(n, 0); ll vhitd0 = 0, vhitd1 = 0; ll ubingo = 0, vbingo = 0; REP(i, m) { ll iu = udic[cards[i]]; ll iv = vdic[cards[i]]; if (iu != -1) { ll i = iu / n; ll j = iu % n; uhitr[i]++; uhitc[j]++; if (i == j) uhitd0++; if (i + j == n-1) uhitd1++; if (uhitr[i] == n) ubingo++; if (uhitc[j] == n) ubingo++; if (i == j) if (uhitd0 == n) ubingo++; if (i + j == n-1) if (uhitd1 == n) ubingo++; } if (iv != -1) { ll i = iv / n; ll j = iv % n; vhitr[i]++; vhitc[j]++; if (i == j) vhitd0++; if (i + j == n-1) vhitd1++; if (vhitr[i] == n) vbingo++; if (vhitc[j] == n) vbingo++; if (i == j) if (vhitd0 == n) vbingo++; if (i + j == n-1) if (vhitd1 == n) vbingo++; } bool uwon = ubingo >= u; bool vwon = vbingo >= v; // cerr << "TURN " << (i+1) << ": " << ubingo << " v.s. " << vbingo << endl; if (uwon && vwon) { std::cout << "DRAW" << endl; return 0; } else if (uwon) { std::cout << "USAGI" << endl; return 0; } else if (vwon) { std::cout << "NEKO" << endl; return 0; } } std::cout << "DRAW" << endl; }
#define _USE_MATH_DEFINES #define INF 0x3f3f3f3f #include <cstdio> #include <iostream> #include <sstream> #include <cmath> #include <cstdlib> #include <algorithm> #include <queue> #include <stack> #include <limits> #include <map> #include <string> #include <cstring> #include <set> #include <deque> #include <bitset> #include <list> #include <cctype> #include <utility> using namespace std; typedef long long ll; typedef pair <int,int> P; typedef pair <int,P > PP; int tx[] = {0,1,0,-1}; int ty[] = {-1,0,1,0}; static const double EPS = 1e-8; static const int MAX_SIZE = 500; int check_paper(bitset<MAX_SIZE>* usagi_horizontal_flags, bitset<MAX_SIZE>* usagi_virtical_flags, bitset<MAX_SIZE>* usagi_diagonal_flags, bitset<MAX_SIZE>* neko_horizontal_flags, bitset<MAX_SIZE>* neko_virtical_flags, bitset<MAX_SIZE>* neko_diagonal_flags, int square_size, int usagi_num, int neko_num){ int usagi_sum = 0; int neko_sum = 0; for(int i=0;i<square_size;i++){ if(usagi_horizontal_flags[i].none()) usagi_sum++; if(usagi_virtical_flags[i].none()) usagi_sum++; if(neko_horizontal_flags[i].none()) neko_sum++; if(neko_virtical_flags[i].none()) neko_sum++; } if(usagi_diagonal_flags[0].none()) usagi_sum++; if(usagi_diagonal_flags[1].none()) usagi_sum++; if(neko_diagonal_flags[0].none()) neko_sum++; if(neko_diagonal_flags[1].none()) neko_sum++; if(square_size == 1){ usagi_sum /= 3; neko_sum /= 3; } bool is_usagi_clear = false; bool is_neko_clear = false; if(usagi_sum >= usagi_num) is_usagi_clear = true; if(neko_sum >= neko_num) is_neko_clear = true; if(is_usagi_clear && is_neko_clear){ //draw return 0; } else if(is_usagi_clear && !is_neko_clear){ return 1; } else if(!is_usagi_clear && is_neko_clear){ return 2; } else { return -1; } } int usagi_paper[1000001]; int neko_paper[1000001]; int main(){ int square_size,usagi_num,neko_num,total_cards; while(~scanf("%d %d %d %d",&square_size,&usagi_num,&neko_num,&total_cards)){ memset(usagi_paper,-1,sizeof(usagi_paper)); memset(neko_paper,-1,sizeof(neko_paper)); for(int y=0;y<square_size;y++){ for(int x=0;x<square_size;x++){ int num; scanf("%d",&num); usagi_paper[num] = y * square_size + x; } } for(int y=0;y<square_size;y++){ for(int x=0;x<square_size;x++){ int num; scanf("%d",&num); neko_paper[num] = y * square_size + x; } } bitset<MAX_SIZE> usagi_horizontal_flags[square_size]; bitset<MAX_SIZE> usagi_virtical_flags[square_size]; bitset<MAX_SIZE> usagi_diagonal_flags[2]; bitset<MAX_SIZE> neko_horizontal_flags[square_size]; bitset<MAX_SIZE> neko_virtical_flags[square_size]; bitset<MAX_SIZE> neko_diagonal_flags[2]; for(int pos=0;pos<square_size;pos++){ for(int bit_idx=0;bit_idx<square_size;bit_idx++){ usagi_horizontal_flags[pos][bit_idx] = true; usagi_virtical_flags[pos][bit_idx] = true; usagi_diagonal_flags[0][bit_idx] = true; usagi_diagonal_flags[1][bit_idx] = true; neko_horizontal_flags[pos][bit_idx] = true; neko_virtical_flags[pos][bit_idx] = true; neko_diagonal_flags[0][bit_idx] = true; neko_diagonal_flags[1][bit_idx] = true; } } const string status[] = {"DRAW","USAGI","NEKO"}; int res = 0; for(int card_idx=0;card_idx<total_cards;card_idx++){ int num; scanf("%d",&num); if(usagi_paper[num] == -1 && neko_paper[num] == -1) continue; if(usagi_paper[num] != -1){ int usagi_x = usagi_paper[num] % square_size; int usagi_y = usagi_paper[num] / square_size; // y: //x:0 1 2 ... 3 4 ... // 1 // 2 usagi_horizontal_flags[usagi_y][usagi_x] = false; usagi_virtical_flags[usagi_x][usagi_y] = false; if(usagi_x==usagi_y){ usagi_diagonal_flags[0][usagi_x] = false; } if(((square_size - 1) - usagi_x) == usagi_y){ usagi_diagonal_flags[1][usagi_x] = false; } } if(neko_paper[num] != -1){ int neko_x = neko_paper[num] % square_size; int neko_y = neko_paper[num] / square_size; // y: //x:0 1 2 ... 3 4 ... // 1 // 2 neko_horizontal_flags[neko_y][neko_x] = false; neko_virtical_flags[neko_x][neko_y] = false; if(neko_x==neko_y){ neko_diagonal_flags[0][neko_x] = false; } if(((square_size - 1) - neko_x) == neko_y){ neko_diagonal_flags[1][neko_x] = false; } } int winner = check_paper(usagi_horizontal_flags, usagi_virtical_flags, usagi_diagonal_flags, neko_horizontal_flags, neko_virtical_flags, neko_diagonal_flags, square_size, usagi_num, neko_num); if(res == 0 && winner != -1 ) res = winner; } printf("%s\n",status[res].c_str()); } }
//include //------------------------------------------ #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <climits> #include <queue> using namespace std; //typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) //constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); int N, U, V, M; int idx(int x, int y){ return y*N+x; } int check(int id, vector<bool>& vb){ if(N == 1){ if(vb[id]) return 1; else return 0; } int x = id % N, y = id / N; int tx, ty, res = 0; for(tx=0;tx<N;++tx) if(!vb[idx(tx,y)]) break; if(tx == N) ++res; for(ty=0;ty<N;++ty) if(!vb[idx(x,ty)]) break; if(ty == N) ++res; if(x == y){ for(tx=0;tx<N;++tx) if(!vb[idx(tx,tx)]) break; if(tx == N) ++res; } if(x+y == N-1){ for(tx=0;tx<N;++tx) if(!vb[idx(tx,N-1-tx)]) break; if(tx == N) ++res; } return res; } int main(){ cin.tie(0); ios_base::sync_with_stdio(false); cin >> N >> U >> V >> M; map<int,int> p1, p2; vector<bool> tab1(N*N, false), tab2(N*N, false); REP(y,N) REP(x,N){ int a; cin >> a; p1[a] = idx(x,y); } REP(y,N) REP(x,N){ int a; cin >> a; p2[a] = idx(x,y); } int ans = 0; REP(m,M){ int a; cin >> a; if(p1.count(a)){ tab1[p1[a]] = true; U -= check(p1[a], tab1); } if(p2.count(a)){ tab2[p2[a]] = true; V -= check(p2[a], tab2); } //cout<<U<<","<<V<<endl; if(U <= 0){ if(V <= 0) ans = 0; else ans = -1; break; } else if(V <= 0){ ans = 1; break; } } if(ans < 0) cout << "USAGI" << endl; else if(ans == 0) cout << "DRAW" << endl; else cout << "NEKO" << endl; return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> VI; typedef vector<VI> VVI; const double PI = 3.14159265358979323846; const double EPS = 1e-12; const int INF = numeric_limits<int>::max() / 2; const int NEG_INF = numeric_limits<int>::min() / 2; const int MOD = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, v, u, m; cin >> n >> u >> v >> m; if (n == 1) { int usa, neko; cin >> usa >> neko; int usasum = 0, nekosum = 0; for (int i = 0; i < m; i++) { int a; cin >> a; if (a == usa) usasum=1; if (a == neko) nekosum=1; if (usasum >= u&&nekosum >= v) { cout << "DRAW" << endl; return 0; } else if (usasum >= u) { cout << "USAGI" << endl; return 0; } else if (nekosum >= v) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; } vector<P> usa(1000001, P(-1, -1)),neko(1000001,P(-1,-1));//usa[i]:=usa?????§i?????????????????§?¨? vector<int> usatate(100000, 0), usayoko(100000, 0); int usasla = 0, usaback = 0; vector<int> nekotate(100000, 0), nekoyoko(100000, 0); int nekosla = 0, nekoback = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int a; cin >> a; usa[a] = P(i, j); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int a; cin >> a; neko[a] = P(i, j); } } int usasum = 0, nekosum = 0; for (int i = 0; i < m; i++) { int a; cin >> a; if (usa[a] != P(-1, -1)) { int x = usa[a].first, y = usa[a].second; //cout<<x<<" "<<y<<endl; usayoko[x]++; usatate[y]++; if (x == y) usasla++; if (x + y == n - 1) usaback++; //cout<<usayoko[x]<<" "<<usatate[y]<<" "<<usasla<<" "<<usaback<<endl; if (usayoko[x] == n) usasum++; if (usatate[y] == n) usasum++; if (x==y&&usasla == n) usasum++; if (x+y==n-1&&usaback == n) usasum++; } if (neko[a] != P(-1, -1)) { int x = neko[a].first, y = neko[a].second; nekoyoko[x]++; nekotate[y]++; if (x == y) nekosla++; if (x + y == n - 1) nekoback++; if (nekoyoko[x] == n) nekosum++; if (nekotate[y] == n) nekosum++; if (x==y&&nekosla == n) nekosum++; if (x+y==n-1&&nekoback == n) nekosum++; } //cout<<usasum<<" "<<nekosum<<endl; if (usasum >= u&&nekosum >= v) { cout << "DRAW" << endl; return 0; } else if (usasum >= u) { cout << "USAGI" << endl; return 0; } else if (nekosum >= v) { cout << "NEKO" << endl; return 0; } else continue; } cout << "DRAW" << endl; }
#include<stdio.h> #include<algorithm> using namespace std; pair<int,int> unagi[1000000]; pair<int,int> wolf[1000000]; int u_row[500]; int u_col[500]; int w_row[500]; int w_col[500]; int main(){ int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d); for(int i=0;i<1000000;i++){ unagi[i]=make_pair(-1,-1); wolf[i]=make_pair(-1,-1); } for(int i=0;i<a;i++) for(int j=0;j<a;j++){ int p; scanf("%d",&p); unagi[p-1]=make_pair(i,j); } for(int i=0;i<a;i++) for(int j=0;j<a;j++){ int p; scanf("%d",&p); wolf[p-1]=make_pair(i,j); } int UL=0; int UR=0; int WL=0; int WR=0; int u=0;int w=0; if(a==1){ for(int i=0;i<d;i++){ int e; scanf("%d",&e);e--; if(~unagi[e].first)u++; if(~wolf[e].first)w++; if(u>=b&&w>=c){ printf("DRAW\n"); return 0; } if(u>=b){ printf("USAGI\n"); return 0; } if(w>=c){ printf("NEKO\n"); return 0; } } printf("DRAW\n"); return 0; } for(int i=0;i<d;i++){ int e; scanf("%d",&e);e--; if(~unagi[e].first){ u_row[unagi[e].first]++; if(u_row[unagi[e].first]==a)u++; u_col[unagi[e].second]++; if(u_col[unagi[e].second]==a)u++; if(unagi[e].first==unagi[e].second){ UL++; if(UL==a)u++; } if(unagi[e].first+unagi[e].second==a-1){ UR++; if(UR==a)u++; } } if(~wolf[e].first){ w_row[wolf[e].first]++; if(w_row[wolf[e].first]==a)w++; w_col[wolf[e].second]++; if(w_col[wolf[e].second]==a)w++; if(wolf[e].first==wolf[e].second){ WL++; if(WL==a)w++; } if(wolf[e].first+wolf[e].second==a-1){ WR++; if(WR==a)w++; } } if(u>=b&&w>=c){ printf("DRAW\n"); return 0; } if(u>=b){ printf("USAGI\n"); return 0; } if(w>=c){ printf("NEKO\n"); return 0; } } printf("DRAW\n"); }
#define _CRT_SECURE_NO_WARNINGS #pragma comment (linker, "/STACK:526000000") #include "bits/stdc++.h" using namespace std; typedef string::const_iterator State; #define eps 1e-11L #define MAX_MOD 1000000007LL #define GYAKU 500000004LL #define MOD 998244353LL #define seg_size 262144 * 4LL #define pb push_back #define mp make_pair typedef long long ll; #define REP(a,b) for(long long (a) = 0;(a) < (b);++(a)) #define ALL(x) (x).begin(),(x).end() void init() { iostream::sync_with_stdio(false); cout << fixed << setprecision(20); } #define int ll map<int, pair<int, int>> mapping[2]; int tate[2][500]; int yoko[2][500]; int cross[2][2]; void solve() { int n, u, v, m; cin >> n >> u >> v >> m; REP(i, 2) { REP(q, n) { REP(j, n) { int a; cin >> a; mapping[i][a] = mp(q, j); } } } if (n == 1) { u *= 4; v *= 4; } REP(i, m) { int a; cin >> a; REP(q, 2) { if (mapping[q].find(a) == mapping[q].end()) continue; pair<int, int> now = mapping[q][a]; tate[q][now.first]++; int down = 0; if (tate[q][now.first] == n) { down++; } yoko[q][now.second]++; if (yoko[q][now.second] == n) { down++; } if (now.first == now.second) { cross[q][0]++; if (cross[q][0] == n) { down++; } } if (now.first == n - now.second - 1) { cross[q][1]++; if (cross[q][1] == n) { down++; } } if (q == 0) { u -= down; } else { v -= down; } } if (u <= 0 && v <= 0) break; if (u <= 0) { cout << "USAGI" << endl; return; } else if(v <= 0){ cout << "NEKO" << endl; return; } } cout << "DRAW" << endl; } #undef int int main() { init(); solve(); }
#define _CRT_SECURE_NO_WARNINGS #include"bits/stdc++.h" #ifdef _DEBUG #define DBG(n) n #else #define DBG(n) #endif #define INF 1e9 #define INFLL 1e18 #define EPS 1e-9 #define REP(i,n) for(ll i=0,i##_len=(n);i<i##_len;++i) #define REP1(i,n) for(ll i=1,i##_len=(n);i<=i##_len;++i) #define REPR(i,n) for(ll i=(n)-1;i>=0;--i) #define REPR1(i,n) for(ll i=(n);i>0;--i) #define REPC(i,obj) for(auto i:obj) #define ALL(obj) (obj).begin(),(obj).end() #define SETP(n) cout<<fixed<<setprecision(n) using namespace std; using ll = long long; template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; } signed main() { ll n = in(), u = in(), v = in(), m = in(); map<ll, pair<ll, ll>>cood_usa; REP(i, n) { REP(j, n) { ll foo = in(); cood_usa[foo] = make_pair(i, j); } } map<ll, pair<ll, ll>>cood_neko; REP(i, n) { REP(j, n) { ll foo = in(); cood_neko[foo] = make_pair(i, j); } } vector<ll>card(m); REP(i, m) card[i] = in(); ll usa_point = 0, neko_point = 0; bool usagi_win = false, neko_win = false; if (n == 1) { REP(i, m) { if (cood_usa.count(card[i]) == 1 && ++usa_point >= u) usagi_win = true; if (cood_neko.count(card[i]) == 1 && ++neko_point >= v)neko_win = true; if (usagi_win && !neko_win) { cout << "USAGI" << endl; break; } else if (!usagi_win && neko_win) { cout << "NEKO" << endl; break; } else if (usagi_win && neko_win) { cout << "DRAW" << endl; break; } } } else { vector<ll>usa_col(n, 0), usa_row(n, 0), neko_col(n, 0), neko_row(n, 0); ll usa_naname1 = 0, usa_naname2 = 0, neko_naname1 = 0, neko_naname2 = 0; REP(i, m) { if (cood_usa.count(card[i]) == 1) { auto cood = cood_usa[card[i]]; if (cood.first == cood.second)++usa_naname1; if (cood.first + cood.second == n - 1)++usa_naname2; if (++usa_col[cood.second] == n)++usa_point; if (++usa_row[cood.first] == n)++usa_point; if (usa_naname1 == n) { ++usa_naname1; ++usa_point; } if (usa_naname2 == n) { ++usa_naname2; ++usa_point; } if (usa_point >= u) usagi_win = true; } if (cood_neko.count(card[i]) == 1) { auto cood = cood_neko[card[i]]; if (cood.first == cood.second)++neko_naname1; if (cood.first + cood.second == n - 1)++neko_naname2; if (++neko_col[cood.second] == n)++neko_point; if (++neko_row[cood.first] == n)++neko_point; if (neko_naname1 == n) { ++neko_naname1; ++neko_point; } if (neko_naname2 == n) { ++neko_naname2; ++neko_point; } if (neko_point >= v)neko_win = true; } if (usagi_win && !neko_win) { cout << "USAGI" << endl; break; } else if (!usagi_win && neko_win) { cout << "NEKO" << endl; break; } else if (usagi_win && neko_win) { cout << "DRAW" << endl; break; } } } if (!usagi_win && !neko_win) { cout << "DRAW" << endl; } }
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} template<class T> inline T sqr(T x) {return x*x;} typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define mp make_pair #define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define exist(s,e) ((s).find(e)!=(s).end()) #define range(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) range(i,0,n) #define clr(a,b) memset((a), (b) ,sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; const double eps = 1e-10; const double pi = acos(-1.0); const ll INF =1LL << 62; const int inf =1 << 29; enum {kRabbit = 0, kCat}; enum {kMigishita = 0, kMigiue}; #define F first #define S second int main(void){ vi t(2); for(int n, m; cin >> n >> t[kRabbit] >> t[kCat] >> m;){ vector<vvi> mats(2, vvi(n, vi(n))); //(num) -> (y, x) vector<map<int, pii>> dic(2); rep(i, 2){ rep(y, n){ rep(x, n){ int num; cin >> num; mats[i][y][x] = num; dic[i][num] = mp(y, x); } } } vvi rowCnt(2, vi(n)); vvi colCnt(2, vi(n)); vvi nanameCnt(2, vi(2)); string res = "UNKNOWN"; rep(i, m){ int num; cin >> num; rep(j, 2){ if(dic[j].find(num) == dic[j].end()) continue; int y = dic[j][num].F, x = dic[j][num].S; rowCnt[j][y]++; colCnt[j][x]++; int delta = 0; if(y == x){ if(++nanameCnt[j][0] == n) delta++; } if(y == n - 1 - x){ if(++nanameCnt[j][1] == n) delta++; } if(rowCnt[j][y] == n) delta++; if(colCnt[j][x] == n) delta++; if(delta >= 1 && n == 1) delta = 1; t[j] -= delta; } if(res != "UNKNOWN") continue; if(t[0] <= 0){ if(t[1] <= 0){ res = "DRAW"; } else res = "USAGI"; } else if(t[1] <= 0) res = "NEKO"; } if(res == "UNKNOWN") res = "DRAW"; cout << res << endl; } return 0; }
#include<iostream> using namespace std; int n,v,u,m,U[1000001],V[1000001],M[100000],sumu=0,sumv=0,x; int HU[501]={},WU[501]={},unaname1=0,unaname2=0; int HV[501]={},WV[501]={},vnaname1=0,vnaname2=0; int main() { for(int i=0;i<1000001;i++){ U[i]=-1; V[i]=-1; } cin>>n>>u>>v>>m; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>x; U[x]=i*n+j; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>x; V[x]=i*n+j; } } for(int i=0;i<m;i++)cin>>M[i]; for(int k=0;k<m;k++){ if(U[M[k]]!=-1){ int a=U[M[k]]/n,b=U[M[k]]%n; HU[a]++; WU[b]++; if(HU[a]==n)sumu++; if(WU[b]==n)sumu++; if(a==b){ unaname1++; if(unaname1==n)sumu++; } if(a+b==n-1){ unaname2++; if(unaname2==n)sumu++; } } if(V[M[k]]!=-1){ int a=V[M[k]]/n,b=V[M[k]]%n; HV[a]++; WV[b]++; if(HV[a]==n)sumv++; if(WV[b]==n)sumv++; if(a==b){ vnaname1++; if(vnaname1==n)sumv++; } if(a+b==n-1){ vnaname2++; if(vnaname2==n)sumv++; } } if(n==1){ sumu=min(sumu,1); sumv=min(sumv,1); } if(sumu>=u && sumv>=v){ cout<<"DRAW"<<endl; break; } if(sumu>=u){ cout<<"USAGI"<<endl; break; } if(sumv>=v){ cout<<"NEKO"<<endl; break; } if(k==m-1)cout<<"DRAW"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef ostringstream OSS; typedef istringstream ISS; typedef long long LL; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<string> VS; typedef vector<VS> VVS; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<PII> VPII; #define Y first #define X second #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(x) (x).begin(),(x).end() #define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY)) #define DUMP( x ) cerr << #x << " = " << ( x ) << endl template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; }; template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); }; const int INF = 0x3f3f3f3f; const LL INFL = 0x3f3f3f3f3f3f3f3fLL; const int DX[]={1,0,-1,0},DY[]={0,-1,0,1}; int main(void) { cin.tie( 0 ); ios::sync_with_stdio( false ); int N, M; VI first_card(2); cin >> N >> first_card[0] >> first_card[1] >> M; vector<map<int, PII>> num2pos(2); for (int i = 0; i < 2; i++) { for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { int a; cin >> a; num2pos[i][a] = MP(y, x); } } } VI ms(M); for (auto &m : ms) cin >> m; // count vector<VI> cnts(2, VI(N * 2 + 2, 0)); VI oks(2); for (int i = 0; i < M; i++) { int m = ms[i]; for (int j = 0; j < 2; j++) { if (!num2pos[j].count(m)) continue; // find PII pos = num2pos[j][m]; oks[j] += ++cnts[j][pos.Y] == N; oks[j] += ++cnts[j][N + pos.X] == N; if (pos.X == pos.Y) { oks[j] += ++cnts[j][N * 2] == N; } if (pos.X + pos.Y == N - 1) { oks[j] += ++cnts[j][N * 2 + 1] == N; } if (N == 1) { oks[j] = 1; } } // ???????????? VB ends(2); for (int j = 0; j < 2; j++) { ends[j] = oks[j] >= first_card[j]; } if (ends[0] ^ ends[1]) { cout << (ends[0] ? "USAGI" : "NEKO") << endl; return 0; } if (ends[0] && ends[1]) { cout << "DRAW" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> P; int a[2][600][600],dx[8]={-1,-1,-1,0,1,1,1,0},dy[8]={-1,0,1,-1,1,0,-1,1}; map<int,P> ma[2]; int n,u,v,m,cu,cv,INF=1<<28; int c[100001]; bool ck(int x,int y) { if(x<0 || x>=n || y<0 || y>=n) return false; return true; } bool check(int z, int k) { if(!ma[k].count(z)) return false; int x=ma[k][z].first,y=ma[k][z].second; a[k][x][y]=1; for(int i=0; i<4; i++) { if(n==1 && i) break; int cnt=1,nx=x,ny=y; for(int j=0; j<n; j++) { nx+=dx[i],ny+=dy[i]; if(!ck(nx,ny)) break; if(a[k][nx][ny]) cnt++; else break; } nx=x,ny=y; for(int j=0; j<n; j++) { nx+=dx[i+4],ny+=dy[i+4]; if(!ck(nx,ny)) break; if(a[k][nx][ny]) cnt++; else break; } if(cnt==n) { if(!k) cu++; else cv++; } } if(!k) return (cu>=u); else return (cv>=v); } int main() { memset(a,0,sizeof(a)); ma[0].clear();ma[1].clear(); cu=0;cv=0; cin >> n >> u >> v >> m; for(int k=0; k<2; k++) { for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { int x; cin >> x; ma[k][x]=P(i,j); } } } int U=INF,V=INF; for(int i=0; i<m; i++) cin >> c[i]; for(int i=0; i<m; i++) { if(check(c[i],0)) U=i; if(check(c[i],1)) V=i; if(U!=INF || V!=INF) break; } if(U<V) cout << "USAGI" << endl; else if(U>V) cout << "NEKO" << endl; else cout << "DRAW" << endl; return 0; }
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <set> #include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <complex> #include <stack> #include <queue> #include <cstdio> #include <cstring> #include <iterator> #include <bitset> #include <unordered_set> #include <unordered_map> #include <fstream> #include <iomanip> #include <cassert> //#include <utility> //#include <memory> //#include <functional> //#include <deque> //#include <cctype> //#include <ctime> //#include <numeric> //#include <list> //#include <iomanip> //#if __cplusplus >= 201103L //#include <array> //#include <tuple> //#include <initializer_list> //#include <forward_list> // //#define cauto const auto& //#else //#endif using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<long long> vll, vLL; typedef vector<vector<long long> > vvll, vvLL; #define VV(T) vector<vector< T > > template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) { v.assign(a, vector<T>(b, t)); } template <class F, class T> void convert(const F &f, T &t) { stringstream ss; ss << f; ss >> t; } #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define reep(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) reep((i),0,(n)) #define ALL(v) (v).begin(),(v).end() #define PB push_back #define F first #define S second #define mkp make_pair #define RALL(v) (v).rbegin(),(v).rend() #define DEBUG #ifdef DEBUG #define dump(x) cout << #x << " = " << (x) << endl; #define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; #else #define dump(x) #define debug(x) #endif #define MOD 1000000007LL #define EPS 1e-8 #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL #define maxs(x,y) x=max(x,y) #define mins(x,y) x=min(x,y) string ans[2] = {"USAGI", "NEKO"}; void mainmain() { int n, m; int c[2]; cin >> n >> c[0] >> c[1] >> m; map<int, pii> a[2]; vvint cnt; initvv(cnt, 4, n, 0); rep(i, n) rep(j, n) { int t; cin >> t; a[0][t] = pii(i, j); } rep(i, n) rep(j, n) { int t; cin >> t; a[1][t] = pii(i, j); } vint d(2); vint cnt1(4); rep(i, m) { int t; cin >> t; if(a[0].count(t)) { pii p = a[0][t]; if(n == ++cnt[2 * 0 + 0][p.F]) d[0]++; if(n > 1 && n == ++cnt[2 * 0 + 1][p.S]) d[0]++; if(n > 1 && p.F == p.S && n == ++cnt1[0]) d[0]++; if(n > 1 && p.F == n - 1 - p.S && n == ++cnt1[1]) d[0]++; } if(a[1].count(t)) { pii p = a[1][t]; if(n == ++cnt[2 * 1 + 0][p.F]) d[1]++; if(n > 1 && n == ++cnt[2 * 1 + 1][p.S]) d[1]++; if(n > 1 && p.F == p.S && n == ++cnt1[2]) d[1]++; if(n > 1 && p.F == n - 1 - p.S && n == ++cnt1[3]) d[1]++; } bool f1 = (d[0] >= c[0]); bool f2 = (d[1] >= c[1]); if(f1 && f2) break; if(f1) { cout << ans[0] << endl; return; } if(f2) { cout << ans[1] << endl; return; } } cout << "DRAW" << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); mainmain(); }
#include <iostream> #include <fstream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <string> #include <set> #include <map> #include <stack> #include <queue> #include <algorithm> using namespace std; #define REP(i,n) for(int i=0; i<n; ++i) #define FOR(i,a,b) for(int i=a; i<=b; ++i) #define FORR(i,a,b) for (int i=a; i>=b; --i) #define pi M_PI typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef pair<int,int> P; typedef pair<ll,ll> PL; const int N = 1000010; int main() { int n, u, v, m; cin >> n >> u >> v >> m; vector<P> pu(N,make_pair(-1, -1)), pn(N,make_pair(-1, -1)); REP(i,n) REP(j,n) { int a; cin >> a; pu[a] = make_pair(i, j); } REP(i,n) REP(j,n) { int a; cin >> a; pn[a] = make_pair(i, j); } VI xu(n), yu(n), ou(2), xn(n), yn(n), on(2); while (m-- > 0 && u > 0 && v > 0) { int a, i, j; cin >> a; i = pu[a].first; j = pu[a].second; if (i != -1) { if (++xu[i] == n) u--; if (++yu[j] == n) u--; if (i == j) if (++ou[0] == n) u--; if (i+j == n-1) if (++ou[1] == n) u--; } i = pn[a].first; j = pn[a].second; if (i != -1) { if (++xn[i] == n) v--; if (++yn[j] == n) v--; if (i == j) if (++on[0] == n) v--; if (i+j == n-1) if (++on[1] == n) v--; } } if (n == 1){ u += 3; v += 3; } string ans; if (u <= 0 && v > 0) ans = "USAGI"; else if (v <= 0 && u > 0) ans = "NEKO"; else ans = "DRAW"; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> P; int a[2][600][600],dx[8]={-1,-1,-1,0,1,1,1,0},dy[8]={-1,0,1,-1,1,0,-1,1}; map<int,P> ma[2]; int n,u,v,m,cu,cv,INF=1<<28; int c[100001]; bool ck(int x,int y) { if(x<0 || x>=n || y<0 || y>=n) return false; return true; } bool check(int z, int k) { if(ma[k].count(z)==0) return false; int x=ma[k][z].first,y=ma[k][z].second; a[k][x][y]=1; for(int i=0; i<4; i++) { if(n==1 && i) break; int cnt=1,nx=x,ny=y; for(int j=0; j<n; j++) { nx+=dx[i],ny+=dy[i]; if(!ck(nx,ny)) break; if(a[k][nx][ny]) cnt++; else break; } nx=x,ny=y; for(int j=0; j<n; j++) { nx+=dx[i+4],ny+=dy[i+4]; if(!ck(nx,ny)) break; if(a[k][nx][ny]) cnt++; else break; } if(cnt==n) { if(!k) cu++; else cv++; } } if(!k) { if(cu>=u) return 1; return 0; } else { if(cv>=v) return 1; return 0; } } int main() { memset(a,0,sizeof(a)); ma[0].clear();ma[1].clear(); cu=0;cv=0; cin >> n >> u >> v >> m; for(int k=0; k<2; k++) { for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { int x; cin >> x; ma[k][x]=P(j,i); } } } int U=INF,V=INF; for(int i=0; i<m; i++) cin >> c[i]; for(int i=0; i<m; i++) { if(check(c[i],0)) U=i; if(check(c[i],1)) V=i; if(U!=INF || V!=INF) break; } if(U<V) cout << "USAGI" << endl; else if(U>V) cout << "NEKO" << endl; else cout << "DRAW" << endl; return 0; }
//#define __USE_MINGW_ANSI_STDIO 0 #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define IN(a, b, x) (a<=x&&x<b) #define MP make_pair #define PB push_back #ifdef int const ll INF = (1LL<<60); #else const int INF = (1LL<<30); #endif const double PI = 3.14159265359; const double EPS = 1e-12; const int MOD = 1000000007; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; PII mp1[1000010], mp2[1000010]; int cnt1[1010], cnt2[1010]; signed main(void) { int n, u, v, m; cin >> n >> u >> v >> m; REP(i, 1000010) mp1[i] = mp2[i] = {-1LL, -1LL}; REP(i, n) REP(j, n) { int x; cin >> x; mp1[x] = {i, j}; } REP(i, n) REP(j, n) { int x; cin >> x; mp2[x] = {i, j}; } if(n == 1) { int ret1 = 0, ret2 = 0, res = -1; REP(i, m) { int a; cin >> a; if(res != -1) continue; // cout << mp1[a].first << " " << mp1[a].second << " " << mp2[a].first << " " << mp2[a].second << endl; if(mp1[a] != MP(-1LL, -1LL)) ret1 = 1; if(mp2[a] != MP(-1LL, -1LL)) ret2 = 1; // cout << ret1 << " " << ret2 << endl; if(ret1 >= u && ret2 >= v) res = 0; else if(ret1 >= u) res = 1; else if(ret2 >= v) res = 2; } if(res == 1) cout << "USAGI" << endl; else if(res == 2) cout << "NEKO" << endl; else cout << "DRAW" << endl; return 0; } /* 0???n-1:???, n???2*n-1:?¨?, 2*n:?????????????????? 2*n+1:?????????????????? */ int ret1 = 0, ret2 = 0, res = -1; REP(i, m) { int a; cin >> a; if(res != -1) continue; if(mp1[a] != MP(-1LL, -1LL)) { cnt1[mp1[a].first]++; if(cnt1[mp1[a].first] == n) ret1++; cnt1[mp1[a].second+n]++; if(cnt1[mp1[a].second+n] == n) ret1++; if(mp1[a].first == n-1-mp1[a].second) { cnt1[2*n]++; if(cnt1[2*n] == n) ret1++; } if(mp1[a].first == mp1[a].second) { cnt1[2*n+1]++; if(cnt1[2*n+1] == n) ret1++; } } if(mp2[a] != MP(-1LL, -1LL)) { cnt2[mp2[a].first]++; if(cnt2[mp2[a].first] == n) ret2++; cnt2[mp2[a].second+n]++; if(cnt2[mp2[a].second+n] == n) ret2++; if(mp2[a].first == n-1-mp2[a].second) { cnt2[2*n]++; if(cnt2[2*n] == n) ret2++; } if(mp2[a].first == mp2[a].second) { cnt2[2*n+1]++; if(cnt2[2*n+1] == n) ret2++; } } // REP(i, 2*n+2) cout << cnt1[i] << " "; cout << endl; // cout << "i:" << i << " " << ret1 << " " << ret2 << endl; if(ret1 >= u && ret2 >= v) { res = 0; } else if(ret1 >= u) { res = 1; } else if(ret2 >= v) { res = 2; } } if(res == 0 || res == -1) cout << "DRAW" << endl; else if(res == 1) cout << "USAGI" << endl; else if(res == 2) cout << "NEKO" << endl; return 0; }
#include <bits/stdc++.h> #define N 1000001 using namespace std; typedef pair <int,int> P; int n,u,v,m,num[N]; P U[N],V[N]; void in(P a[]){ for(int i=1;i<=n;i++) for(int j=1,b;j<=n;j++) cin>>b,a[b]=P(i,j); } int game(P A[],int B){ int i,ta[501]={},yo[501]={},X[2]={},cnt=n!=1? 0:-3; for(i=0;cnt<B&&i<=m;i++){ int y=A[num[i]].first,x=A[num[i]].second; if(x==0)continue; X[0]+=(x==y); X[1]+=(x+y==n+1); if(X[0]==n) X[0]++,cnt++; if(X[1]==n) X[1]++,cnt++; cnt+=(++ta[y]==n)+(++yo[x]==n); } return i; } int main(){ cin>>n>>u>>v>>m; in(U),in(V); for(int i=0;i<m;i++) cin>>num[i]; int Uscore=game(U,u),Vscore=game(V,v); if(Uscore!=Vscore)cout<<(Uscore<Vscore ? "USAGI":"NEKO")<<endl; else cout<<"DRAW"<<endl; return 0; }
#include <bits/stdc++.h> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int,P> pip; typedef vector<pip> vip; const int inf=1<<29; const ll INF=1ll<<60; const double pi=acos(-1); const double eps=1e-9; const ll mod=1e9+7; const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1}; int n,m; vi c; int f(vvi a,int t){ if(n==1){ if(t>=2) return m; for(int i=0;i<m;i++) if(a[0][0]==c[i]) return i; return m; } vi b(n),d(n); int t1=0,t2=0; vp ind(1000001,{-1,-1}); for(int i=0;i<n;i++) for(int j=0;j<n;j++) ind[a[i][j]]={i,j}; for(int i=0;i<m;i++){ P p=ind[c[i]]; int x=p.first,y=p.second; if(x==-1) continue; b[x]++; d[y]++; if(b[x]==n) t--; if(d[y]==n) t--; if(x==y){ t1++; if(t1==n) t--; } if(n-x-1==y){ t2++; if(t2==n) t--; } if(t<=0) return i; } return m; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int x,y; cin>>n>>x>>y>>m; vvi a(n,vi(n)),b(n,vi(n)); c=vi(m); for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j]; for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>b[i][j]; for(auto &i:c) cin>>i; int p=f(a,x),q=f(b,y); if(p==q) cout<<"DRAW"<<endl; else if(p<q) cout<<"USAGI"<<endl; else cout<<"NEKO"<<endl; }
#include <iostream> #include <sstream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> using namespace std; #define FOR(i,k,n) for(int i=(k); i<(int)n; ++i) #define REP(i,n) FOR(i,0,n) #define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) typedef pair<int,int> P; struct Animal{ int size; bool bingo[500][500]; map<int,P> point; int count; Animal(int s){ count = 0; memset(bingo,0,sizeof(bingo)); size = s; } void print(){ cout<<count<<endl; REP(y,size){ REP(x,size){ printf("%d ",(int)bingo[y][x]); } putchar('\n'); } putchar('\n'); } void insert(int n,int x, int y){ point[n] = P(x,y); } void drow(int n){ if(point.find(n)!=point.end()){ P p = point[n]; bingo[p.second][p.first] = true; bool okr = true; bool okc = true; bool okd1 = (p.first == p.second); bool okd2 = (p.first + p.second == size-1); REP(i,size){ okr &= bingo[p.second][i]; okc &= bingo[i][p.first]; okd1 &= bingo[i][i]; okd2 &= bingo[i][size-1-i]; } count += (okr+okc+okd1+okd2); } } bool check(int n){ if(size == 1) return (int)(count>0) >= n; return count >= n; } }; int main(){ int n,u,v,m,d; cin>>n>>u>>v>>m; Animal usagi(n); Animal neko(n); REP(y,n)REP(x,n){ scanf("%d",&d); usagi.insert(d,x,y); } REP(y,n)REP(x,n){ scanf("%d",&d); neko.insert(d,x,y); } bool gameover = false; REP(i,m){ scanf("%d",&d); if(!gameover){ usagi.drow(d); neko.drow(d); if(usagi.check(u)&&neko.check(v)){ cout<<"DRAW"<<endl; gameover = true; }else if(usagi.check(u)){ cout<<"USAGI"<<endl; gameover = true; }else if(neko.check(v)){ cout<<"NEKO"<<endl; gameover = true; } } } if(!gameover){ cout<<"DRAW"<<endl; } return 0; }
#include<cstdio> #include<map> #define fst first #define snd second using namespace std; typedef pair<int,int> pt; typedef long long int lli; int usa_x[600], usa_y[600], usa_xy[2]; int cat_x[600], cat_y[600], cat_xy[2]; int usa_cnt, cat_cnt; map<lli,pt> usa_board, cat_board; int main(void) { int n,u,v,m; scanf("%d%d%d%d",&n,&u,&v,&m); if(n==1) u*=4, v*=4; for(int i=0; i<n; i++) for(int j=0; j<n; j++) { lli x; scanf("%lld",&x); usa_board[x] = pt(j,i); } for(int i=0; i<n; i++) for(int j=0; j<n; j++) { lli a; scanf("%lld",&a); cat_board[a] = pt(j,i); } for(int i=0; i<m; i++) { lli a; scanf("%lld",&a); if(usa_board.find(a) != usa_board.end()) { int x = usa_board[a].fst; int y = usa_board[a].snd; usa_x[x]++; usa_y[y]++; if(usa_x[x] == n) usa_cnt++; if(usa_y[y] == n) usa_cnt++; if(x==y) { usa_xy[0]++; if(usa_xy[0] == n) usa_cnt++; } if(x+y==n-1) { usa_xy[1]++; if(usa_xy[1] == n) usa_cnt++; } } if(cat_board.find(a) != cat_board.end()) { int x = cat_board[a].fst; int y = cat_board[a].snd; cat_x[x]++; cat_y[y]++; if(cat_x[x] == n) cat_cnt++; if(cat_y[y] == n) cat_cnt++; if(x==y) { cat_xy[0]++; if(cat_xy[0] == n) cat_cnt++; } if(x+y==n-1) { cat_xy[1]++; if(cat_xy[1] == n) cat_cnt++; } } if(usa_cnt >= u || cat_cnt >= v) break; } if(usa_cnt >= u && cat_cnt < v) puts("USAGI"); else if(usa_cnt < u && cat_cnt >= v) puts("NEKO"); else puts("DRAW"); return 0; }
#include<cstdio> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int n,m,card[100000]; int solve(const int A[500][500],int win){ // win : 揃えるべき列の個数 static int X[1000001],Y[1000001]; rep(i,1000001) X[i]=-1; rep(i,n) rep(j,n) X[A[i][j]]=j, Y[A[i][j]]=i; int tate[500]={},yoko[500]={},naname1=0,naname2=0; rep(i,m){ if(X[card[i]]==-1) continue; int x=X[card[i]],y=Y[card[i]]; if(++tate[x]==n) win--; if(++yoko[y]==n) win--; if(x-y== 0 && ++naname1==n) win--; if(x+y==n-1 && ++naname2==n) win--; if(n==1) win+=3; // コーナーケース!!!!! if(win<=0) return i; } return m; } int main(){ int usagi,neko; scanf("%d%d%d%d",&n,&usagi,&neko,&m); static int U[500][500],N[500][500]; rep(i,n) rep(j,n) scanf("%d",U[i]+j); rep(i,n) rep(j,n) scanf("%d",N[i]+j); rep(i,m) scanf("%d",card+i); int ans_u=solve(U,usagi); int ans_n=solve(N,neko); if (ans_u<ans_n) puts("USAGI"); else if(ans_u>ans_n) puts("NEKO"); else puts("DRAW"); return 0; }
#include <iostream> #include <stdio.h> #include <math.h> #include <utility> using namespace std; typedef pair<int, int> P; int n, u, v, m; int a[505][505], b[505][505]; bool vala[1000005], valb[1000005]; P reva[1000005], revb[1000005]; bool useda[505][505], usedb[505][505]; int rowa[505], rowb[505], cola[505], colb[505]; int diaga, diagb, cdiaga, cdiagb; int main(void) { cin >> n >> u >> v >> m; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ cin >> a[i][j]; reva[a[i][j]] = make_pair(i, j); vala[a[i][j]] = true; } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ cin >> b[i][j]; revb[b[i][j]] = make_pair(i, j); valb[b[i][j]] = true; } } int x; for(int q = 0; q < m; q++){ cin >> x; //cout << x << endl; bool wina = false, winb = false; if(vala[x]){ int i = reva[x].first, j = reva[x].second; useda[i][j] = true; rowa[i]++, cola[j]++; if(i == j) diaga++; if(i+j == n+1) cdiaga++; int cnt = 0; for(int k = 1; k <= n; k++){ if(rowa[k] >= n) cnt++; if(cola[k] >= n) cnt++; } if(diaga >= n) cnt++; if(cdiaga >= n) cnt++; if(n == 1) cnt = min(cnt, 1); wina = (cnt >= u); } if(valb[x]){ int i = revb[x].first, j = revb[x].second; usedb[i][j] = true; rowb[i]++, colb[j]++; if(i == j) diagb++; if(i+j == n+1) cdiagb++; int cnt = 0; for(int k = 1; k <= n; k++){ if(rowb[k] >= n) cnt++; if(colb[k] >= n) cnt++; } if(diagb >= n) cnt++; if(cdiagb >= n) cnt++; if(n == 1) cnt = min(cnt, 1); winb = (cnt >= v); } if(wina && !winb){ cout << "USAGI" << endl; return 0; } if(!wina && winb){ cout << "NEKO" << endl; return 0; } if(wina && winb){ cout << "DRAW" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; #define MAX 1000005 int main(){ bool e[2][MAX]={{}}; //P s[2][MAX]; //int sx[2][MAX]={{}}; //int sy[2][MAX]={{}}; int st[2][500][500]={{{}}}; int n,u,v,m; int i,j,k; cin >> n >> u >> v >> m; for(i=0;i<n;i++){ for(j=0;j<n;j++){ cin >> k; e[0][k]=true; st[0][i][j]=k; } } for(i=0;i<n;i++){ for(j=0;j<n;j++){ cin >> k; e[1][k]=true; st[1][i][j]=k; } } int col[2][500]={{}}; int row[2][500]={{}}; bool bcol[2][500]={{}}; bool brow[2][500]={{}}; int nnm[2][2]={{}}; bool bnnm[2][2]={{}}; int c[2]={}; int ans=0; int x,y; for(i=0;i<m;i++){ cin >> k; for(j=0;j<2;j++){ if(e[j][k]){ x=-1; for(int a=0;a<n;a++){ for(int b=0;b<n;b++){ if(st[j][a][b]==k){ x=a;y=b;break; } } if(x!=-1) break; } if(!bcol[j][x]){ col[j][x]++; if(col[j][x]==n){ c[j]++; bcol[j][x]=true; } } if(n>1){ if(!brow[j][y]){ row[j][y]++; if(row[j][y]==n){ c[j]++; brow[j][y]=true; } } if(!bnnm[j][0]){ if(x==y) nnm[j][0]++; if(nnm[j][0]==n){ c[j]++; bnnm[j][0]=true; } } if(!bnnm[j][1]){ if(x+y+1==n) nnm[j][1]++; if(nnm[j][1]==n){ c[j]++; bnnm[j][1]=true; } } } } } //cout << k <<":"<< c[0] << c[1] << endl; if(u<=c[0]&&v<=c[1]){ break; }else if(u<=c[0]){ ans=1; break; }else if(v<=c[1]){ ans=2; break; } } if(ans==0) cout << "DRAW" << endl; if(ans==1) cout << "USAGI" << endl; if(ans==2) cout << "NEKO" << endl; return 0; }
#include <cstdio> #include <cstring> #include <algorithm> #include <map> using namespace std; #define rep(i,j) REP((i), 0, (j)) #define REP(i,j,k) for(int i=(j);(i)<(k);++i) int N,U,V,M; int u[512][512], n[512][512]; map<int, int>mu,mn; int dy[]={-1,1,-1,1,-1,1,0,0}, dx[]={-1,1,0,0,1,-1,1,-1}; int countLine(int y, int x, int a[512][512]){ int res = 0, f; f = 1; rep(i,N) f &= (a[y][i]==0); res += f; f = 1; rep(i,N) f &= (a[i][x]==0); res += f; if(y==x){ f = 1; rep(i,N) f &= (a[i][i]==0); res += f; } if(y==N-x-1){ f = 1; rep(i,N) f &= (a[i][N-i-1]==0); res += f; } if(res>0 && N==1) res = 1; return res; } int main(){ int x[100005]; scanf("%d%d%d%d",&N,&U,&V,&M); rep(i,N) rep(j,N){ scanf("%d", &u[i][j]); mu[u[i][j]] = i*N+j; } rep(i,N) rep(j,N){ scanf("%d", &n[i][j]); mn[n[i][j]] = i*N+j; } rep(i,M) scanf("%d", x+i); int ru = 0, rn = 0; rep(i,M){ if(mu.find(x[i]) != mu.end()){ int pos = mu[x[i]]; u[pos/N][pos%N] = 0; ru += countLine(pos/N, pos%N, u); } if(mn.find(x[i]) != mn.end()){ int pos = mn[x[i]]; n[pos/N][pos%N] = 0; rn += countLine(pos/N, pos%N, n); } if(ru >= U && rn >= V){ puts("DRAW"); return 0;} else if(ru >= U){ puts("USAGI"); return 0; } else if(rn >= V){ puts("NEKO"); return 0; } } puts("DRAW"); return 0; }
#include<iostream> #include<map> using namespace std; int n,u,v,m; bool U[500][500],N[500][500]; map<int,pair<int,int> >usa,ne; int main() { cin>>n>>u>>v>>m; if(n==1) { u*=4; v*=4; } for(int i=0;i<n;i++)for(int j=0;j<n;j++) { int a;cin>>a; usa[a]=make_pair(i,j); } for(int i=0;i<n;i++)for(int j=0;j<n;j++) { int a;cin>>a; ne[a]=make_pair(i,j); } for(;m--;) { int a;cin>>a; int x,y; bool f1,f2; if(usa.find(a)!=usa.end()) { x=usa[a].first,y=usa[a].second; U[x][y]=1; f1=1,f2=1; for(int i=0;i<n;i++)f1&=U[x][i],f2&=U[i][y]; if(f1)u--; if(f2)u--; if(x==y) { f1=1; for(int i=0;i<n;i++)f1&=U[i][i]; if(f1)u--; } if(x==n-y-1) { f1=1; for(int i=0;i<n;i++)f1&=U[i][n-i-1]; if(f1)u--; } } if(ne.find(a)!=ne.end()) { x=ne[a].first,y=ne[a].second; N[x][y]=1; f1=1,f2=1; for(int i=0;i<n;i++)f1&=N[x][i],f2&=N[i][y]; if(f1)v--; if(f2)v--; if(x==y) { f1=1; for(int i=0;i<n;i++)f1&=N[i][i]; if(f1)v--; } if(x==n-y-1) { f1=1; for(int i=0;i<n;i++)f1&=N[i][n-i-1]; if(f1)v--; } } if(u<=0&&v<=0) { cout<<"DRAW"<<endl; return 0; } else if(u<=0) { cout<<"USAGI"<<endl; return 0; } else if(v<=0) { cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; }
#include <iostream> #include <iomanip> #include <sstream> #include <cstdio> #include <string> #include <vector> #include <algorithm> #include <complex> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #include <climits> #include <queue> #include <set> #include <map> #include <valarray> #include <bitset> #include <stack> using namespace std; #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef pair<int,int> pii; const int INF = 1<<29; const double PI = acos(-1); const double EPS = 1e-8; vector<pii> pos[2][1000000]; int card[100000]; int tate[2][500]; int yoko[2][500]; int naname1[2]; int naname2[2]; bool mita[1000000]; int num[2]; int main() { int n,u[2],m; cin>>n>>u[0]>>u[1]>>m; REP(k,2) { REP(i,n)REP(j,n) { int a;cin >> a;a--; pos[k][a].push_back(pii(i,j)); } } REP(i,m)cin>>card[i]; if (n==1) u[0]*=4,u[1]*=4; REP(i,m) { card[i]--; if (mita[card[i]]) continue; mita[card[i]] = 1; int win = 0; REP(j,2) { FOR(it, pos[j][card[i]]) { int y=it->first,x=it->second; if (++yoko[j][y]==n) num[j]++; if (++tate[j][x]==n) num[j]++; if (x==y) { if (++naname1[j]==n) num[j]++; } if (x==n-y-1) { if (++naname2[j]==n) num[j]++; } } if (num[j]>=u[j]) win |= 1<<j; } // cout << card[i] << endl; // cout << num[0] << " " << num[1] << endl; if (win) { if (win == 1) cout << "USAGI" << endl; else if (win == 2) cout << "NEKO" << endl; else if (win == 3) cout << "DRAW" << endl; return 0; } } cout << "DRAW" << endl; }
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <climits> #include <vector> #include <map> #include <set> #include <list> #include <stack> #include <queue> #include <algorithm> #include <iostream> #include <string> #define REP(i,n) for(int i=0;i<n;++i) #define REPR(i,n) for(int i=n;i>=0;--i) #define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr) #define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr) #define FOR(i,a,b) for(int i=a;i<b;++i) #define SORT(v,n) sort(v, v+n) #define SORTV(v) sort(v.begin(), v.end()) #define ALL(v) v.begin(),v.end() #define llong long long #define INF 999999999 #define SUR 1000000007 #define pb push_back #define pf push_front #define MP make_pair int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0}; using namespace std; typedef pair<int,int> pii; int a[500][500], b[500][500]; struct data{ //bool line_x[500] = {}, line_y[500] = {}; bool used[500][500] = {}; bool naname[2] = {}; }; int main(){ int n, u, v, m; scanf("%d %d %d %d", &n, &u, &v, &m); map<int, pii> mp1, mp2; REP(i,n){ REP(j,n){ scanf("%d", &a[i][j]); mp1[a[i][j]] = MP(i, j); } } REP(i,n){ REP(j,n){ scanf("%d", &b[i][j]); mp2[b[i][j]] = MP(i, j); } } data usa, neko; vector<int> card_v(m); REP(i,m){ scanf("%d", &card_v[i]); } if(n == 1){ REP(i,m){ int card = card_v[i]; if(a[0][0] == card){ u--; } if(b[0][0] == card){ v--; } if(u <= 0 && v <= 0){ printf("DRAW\n"); return 0; }else if(u <= 0){ printf("USAGI\n"); return 0; }else if(v <= 0){ printf("NEKO\n"); return 0; } } printf("DRAW\n"); return 0; } REP(i,m){ int card = card_v[i]; //USAGI if(mp1.find(card) != mp1.end()){ int y = mp1[card].first, x = mp1[card].second; usa.used[y][x] = true; bool isLine = true; REP(j,n){ if(!usa.used[y][j]){ isLine = false; break; } } if(isLine){ u--; } isLine = true; REP(j,n){ if(!usa.used[j][x]){ isLine = false; break; } } if(isLine){ u--; } //naname if(x == y){ isLine = true; REP(j,n){ if(!usa.used[j][j]){ isLine =false; break; } } if(isLine){ u--; } } if((x + y) == n - 1){ isLine = true; REP(j,n){ if(!usa.used[j][n-j-1]){ isLine = false; break; } } if(isLine){ u--; } } } //NEKO if(mp2.find(card) != mp2.end()){ int y = mp2[card].first, x = mp2[card].second; neko.used[y][x] = true; bool isLine = true; REP(j,n){ if(!neko.used[y][j]){ isLine = false; break; } } if(isLine){ v--; } isLine = true; REP(j,n){ if(!neko.used[j][x]){ isLine = false; break; } } if(isLine){ v--; } //naname if(x == y){ isLine = true; REP(j,n){ if(!neko.used[j][j]){ isLine =false; break; } } if(isLine){ v--; } } if((x + y) == n - 1){ isLine = true; REP(j,n){ if(!neko.used[j][n-j-1]){ isLine = false; break; } } if(isLine){ v--; } } } /* REP(i,n){ REP(j,n){ cout << usa.used[i][j] << " "; } cout << endl; } REP(i,n){ REP(j,n){ cout << neko.used[i][j] << " "; } cout << endl; } */ if(u <= 0 && v <= 0){ printf("DRAW\n"); return 0; }else if(u <= 0){ printf("USAGI\n"); return 0; }else if(v <= 0){ printf("NEKO\n"); return 0; } //cout << u << " " << v << endl; } printf("DRAW\n"); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < n; i++) using namespace std; typedef pair<int,int> P; int n, v[2], M; map<int,P> m[2]; int tate[2][500]; int yoko[2][500]; int nana[2][2]; int sum[2]; bool ok[2]; int main(){ cin >> n >> v[0] >> v[1] >> M; rep(u,2) rep(i,n) rep(j,n){ int x; cin >> x; m[u][x] = P(i+1,j+1); } if(n == 1){ int num; cin >> num; if(m[0][num].first != 0 && v[0] == 1) ok[0] = true; if(m[1][num].first != 0 && v[1] == 1) ok[1] = true; if(ok[0] == true && ok[1] == true){ puts("DRAW"); return 0; } if(ok[0] == true){ puts("USAGI"); return 0; } if(ok[1] == true){ puts("NEKO"); return 0; } puts("DRAW"); return 0; } rep(i,M){ int num; cin >> num; rep(j,2){ P p = m[j][num]; if(p.first == 0) continue; p.first--; p.second--; tate[j][p.first]++; yoko[j][p.second]++; if(tate[j][p.first] == n) sum[j]++; if(yoko[j][p.second] == n) sum[j]++; if(p.first == p.second){ nana[j][0]++; if(nana[j][0] == n) sum[j]++; } if(p.first+p.second==n-1){ nana[j][1]++; if(nana[j][1] == n) sum[j]++; } if(sum[j] >= v[j]) ok[j] = true; } if(ok[0] == true && ok[1] == true){ puts("DRAW"); return 0; } if(ok[0] == true){ puts("USAGI"); return 0; } if(ok[1] == true){ puts("NEKO"); return 0; } } puts("DRAW"); }
#include<bits/stdc++.h> using namespace std; int n,u,v,m,x; map<int,int> Ai,Aj,Bi,Bj,Af,Bf; int sumA,sumB; int Ay[1000],Ax[1000],Ac,Ad; int By[1000],Bx[1000],Bc,Bd; void init(){ sumA=0; Ac=0; Ad=0; sumB=0; Bc=0; Bd=0; Ai.clear(); Aj.clear(); Af.clear(); Bi.clear(); Bj.clear(); Bf.clear(); for(int i=0;i<1000;i++){ Ay[i]=0; Ax[i]=0; By[i]=0; Bx[i]=0; } } int M[100000]; void solve(){ for(int i=0;i<m;i++)cin>>M[i]; for(int i=0;i<m;i++){ x=M[i]; int ai=Ai[x]; int aj=Aj[x]; int bi=Bi[x]; int bj=Bj[x]; if(Af[x]){ Ay[ai]++; Ax[aj]++; if(Ay[ai]==n)sumA++; if(Ax[aj]==n)sumA++; if(ai==aj){ Ac++; if(Ac==n)sumA++; } if(ai+aj==n-1){ Ad++; if(Ad==n)sumA++; } } if(Bf[x]){ By[bi]++; Bx[bj]++; if(By[bi]==n)sumB++; if(Bx[bj]==n)sumB++; if(bi==bj){ Bc++; if(Bc==n)sumB++; } if(bi+bj==n-1){ Bd++; if(Bd==n)sumB++; } } //cout<<x<<' '<<sumA<< ' ' <<sumB<<endl; if(sumA>=u&&sumB>=v){ cout<<"DRAW"<<endl; return; }else if(sumA>=u){ cout<<"USAGI"<<endl; return; }else if(sumB>=v){ cout<<"NEKO"<<endl; return; } } cout<<"DRAW"<<endl; } int main(){ cin>>n>>u>>v>>m; init(); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>x; Ai[x]=i; Aj[x]=j; Af[x]=1; } } if(n==1){ u+=3; v+=3; } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>x; Bi[x]=i; Bj[x]=j; Bf[x]=1; } } solve(); return 0; }
#include <cstdio> #include <cstdint> #include <vector> #include <algorithm> #include <map> size_t achieve(const std::vector<std::vector<int>>& bingo, const std::map<int, size_t>& nth, size_t u) { size_t n = bingo.size(); std::vector<std::vector<size_t>> a(n, std::vector<size_t>(n, -1)); for (size_t i = 0; i < n; ++i) for (size_t j = 0; j < n; ++j) { auto it = nth.find(bingo[i][j]); if (it == nth.end()) continue; a[i][j] = it->second; } // for (size_t i = 0; i < n; ++i) // for (size_t j = 0; j < n; ++j) // fprintf(stderr, "%jd%c", a[i][j], j+1<n? ' ':'\n'); std::vector<size_t> res; res.reserve(2*n+2); for (size_t i = 0; i < n; ++i) { res.push_back(*std::max_element(a[i].begin(), a[i].end())); size_t cur = 0; for (size_t j = 0; j < n; ++j) cur = std::max(cur, a[j][i]); res.push_back(cur); } size_t d0 = 0; size_t d1 = 0; for (size_t i = 0; i < n; ++i) { d0 = std::max(d0, a[i][i]); d1 = std::max(d1, a[i][n-i-1]); } res.push_back(d0); res.push_back(d1); if (n == 1) res.resize(1); // ??? --u; if (res.size() <= u) return -1; // for (size_t i = 0; i < res.size(); ++i) // fprintf(stderr, "%zd%c", res[i], i+1<res.size()? ' ':'\n'); std::sort(res.begin(), res.end()); // for (size_t i = 0; i < res.size(); ++i) // fprintf(stderr, "%zd%c", res[i], i+1<res.size()? ' ':'\n'); return res[u]; } int main() { size_t n, m; size_t u, v; scanf("%zu %zu %zu %zu", &n, &u, &v, &m); std::vector<std::vector<int>> usagi(n, std::vector<int>(n)); auto neko = usagi; for (size_t i = 0; i < n; ++i) for (size_t j = 0; j < n; ++j) scanf("%d", &usagi[i][j]); for (size_t i = 0; i < n; ++i) for (size_t j = 0; j < n; ++j) scanf("%d", &neko[i][j]); std::map<int, size_t> nth; for (size_t i = 0; i < m; ++i) { int d; scanf("%d", &d); nth[d] = i; } size_t pyon = achieve(usagi, nth, u); size_t nyan = achieve(neko, nth, v); if (pyon < nyan) { puts("USAGI"); } else if (pyon > nyan) { puts("NEKO"); } else { puts("DRAW"); } }
#include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <fstream> #include <functional> #include <bitset> #define chmin(a, b) ((a)=min((a), (b))) #define chmax(a, b) ((a)=max((a), (b))) #define fs first #define sc second #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<int, int, int> T; const ll MOD=1e9+7; const ll INF=1e18; const double pi=acos(-1); const double eps=1e-10; int dx[]={1, 0, -1, 0}; int dy[]={0, -1, 0, 1}; int main(){ int n, u, v, m; cin>>n>>u>>v>>m; map<int, P> Uboard, Nboard; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ int x; cin>>x; Uboard[x] = P(i, j); } } for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ int x; cin>>x; Nboard[x] = P(i, j); } } vector<int> Uh(n, n), Uw(n, n), Nh(n, n), Nw(n, n); int Ud1=n, Ud2=n, Nd1=n, Nd2=n; bool Uvalid=false, Nvalid=false; int Ucnt=0, Ncnt=0; vector<int> q(m); for(int i=0; i<m; i++) cin>>q[i]; for(int i=0; i<m; i++){ int x=q[i]; auto itr = Uboard.find(x); if(itr != Uboard.end()){ int cy = Uboard[x].fs; int cx = Uboard[x].sc; Uh[cx]--; if(Uh[cx] == 0) Ucnt++; Uw[cy]--; if(Uw[cy] == 0) Ucnt++; if(cy == cx){ Ud1--; if(Ud1 == 0) Ucnt++; } if(cy == (n - 1 - cx)){ Ud2--; if(Ud2 == 0) Ucnt++; } } itr = Nboard.find(x); if(itr != Nboard.end()){ int cy = Nboard[x].fs; int cx = Nboard[x].sc; Nh[cx]--; if(Nh[cx] == 0) Ncnt++; Nw[cy]--; if(Nw[cy] == 0) Ncnt++; if(cy == cx){ Nd1--; if(Nd1 == 0) Ncnt++; } if(cy == (n - 1 - cx)){ Nd2--; if(Nd2 == 0) Ncnt++; } } if(n == 1){ chmin(Ucnt, 1); chmin(Ncnt, 1); } if(u <= Ucnt){ Uvalid = true; } if(v <= Ncnt){ Nvalid = true; } if(Uvalid && Nvalid){ cout << "DRAW" << endl; return 0; } if(Uvalid && !Nvalid){ cout << "USAGI" << endl; return 0; } if(!Uvalid && Nvalid){ cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; }
#include <bits/stdc++.h> using namespace std; #define MAX 1000001 int ru[MAX],cu[MAX]; int rv[MAX],cv[MAX]; int a[MAX],b[MAX],c,d; int e[MAX],f[MAX],g,h; int main(){ int N,u,v,m,in; cin >> N >> u >> v >> m; for(int i = 0 ; i < MAX ; i++){ ru[i] = cu[i] = rv[i] = cv[i] = -1; a[i] = b[i] = N; e[i] = f[i] = N; } c = d = g = h = N; for(int i = 0 ; i < N ; i++){ for(int j = 0 ; j < N ; j++){ cin >> in; ru[in] = i; cu[in] = j; } } for(int i = 0 ; i < N ; i++){ for(int j = 0 ; j < N ; j++){ cin >> in; rv[in] = i; cv[in] = j; } } bool usagi = false,neko = false; int x; while(m--){ cin >> x; if(N == 1){ if(ru[x] != -1){ u--; } if(rv[x] != -1){ v--; } if(u == 0){ usagi = true; } if(v == 0){ neko = true; } if(usagi || neko){ break; } continue; } if(ru[x] != -1){ a[ru[x]]--; b[cu[x]]--; if(ru[x] == cu[x]){ if( N/2 == ru[x] && (N & 1) ){ c--; d--; }else{ c--; } if(c == 0){ c = -1; u--; } if(d == 0){ d = -1; u--; } } else if(ru[x]+cu[x] == N-1){ d--; if(d == 0){ d = -1; u--; } } if(a[ru[x]] == 0){ ru[x] = -1; u--; } if(b[cu[x]] == 0){ cu[x] = -1; u--; } } if(rv[x] != -1){ e[rv[x]]--; f[cv[x]]--; if(rv[x] == cv[x]){ if(N/2 == rv[x] && (N&1) ){ g--; h--; }else{ g--; } if(g == 0){ g = -1; v--; } if(h == 0){ h = -1; v--; } } else if(rv[x]+cv[x] == N-1){ h--; if(h == 0){ h = -1; v--; } } if(e[rv[x]] == 0){ rv[x] = -1; v--; } if(f[cv[x]] == 0){ cv[x] = -1; v--; } } if(u <= 0){ usagi = true; } if(v <= 0){ neko = true; } if(usagi || neko){ break; } } while( cin >> x ){} if((usagi && neko) || (!usagi && !neko)){ cout << "DRAW" << endl; }else if(usagi){ cout << "USAGI" << endl; }else{ cout << "NEKO" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef pair<int, int> P; int main() { int n, u, v, m; cin >> n >> u >> v >> m; vector<P> usa(1000010, P(-1, -1)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int a; cin >> a; usa[a] = P(i, j); } } vector<P> nek(1000010, P(-1, -1)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int a; cin >> a; nek[a] = P(i, j); } } vector<int> cui(n, 0); vector<int> cuj(n, 0); vector<int> cni(n, 0); vector<int> cnj(n, 0); int cuc1 = 0, cuc2 = 0, cnc1 = 0, cnc2 = 0; int cu = 0, cn = 0; for (int i = 0; i < m; ++i) { int p; cin >> p; int wu = 0, wn = 0; if (usa[p].first != -1) { if (++cui[usa[p].first] == n) ++cu; if (++cuj[usa[p].second] == n) ++cu; if (usa[p].first == usa[p].second && ++cuc1 == n) ++cu; if (usa[p].first + usa[p].second == n - 1 && ++cuc2 == n) ++cu; if (n == 1) cu = min(cu, 1); wu = cu >= u; } if (nek[p].first != -1) { if (++cni[nek[p].first] == n) ++cn; if (++cnj[nek[p].second] == n) ++cn; if (nek[p].first == nek[p].second && ++cnc1 == n) ++cn; if (nek[p].first + nek[p].second == n - 1 && ++cnc2 == n) ++cn; if (n == 1) cn = min(cn, 1); wn = cn >= v; } if (wu && wn) { puts("DRAW"); return 0; } if (wu) { puts("USAGI"); return 0; } if (wn) { puts("NEKO"); return 0; } } puts("DRAW"); return 0; }
#include<bits/stdc++.h> #define M 100000 #define Y second #define X first #define N 500 using namespace std; typedef pair<int,int> P; typedef pair<P,P> P1; int n,u,v,m,a[2][N][N],b,f1,f2; bool usa[N][N],nek[N][N]; int usac[N*2+2],cu; int nekc[N*2+2],cn; vector<P1> x; vector<P> d; set<int> s; map<int,P> z[2]; int Bynary_Search(int k){ int L=0,R=d.size(); while(L<R){ int Mid=(L+R)/2; if(d[Mid].X<k)L=Mid+1; else R=Mid; } if(d[L].X==k)return L; return -1; } int main(){ cin>>n>>u>>v>>m; for(int i=0;i<2;i++) for(int j=0;j<n;j++) for(int k=0;k<n;k++){ cin>>a[i][j][k]; z[i].insert(make_pair(a[i][j][k],P(j,k))); s.insert(a[i][j][k]); } for(int i=0;i<m;i++){ cin>>b; d.push_back(P(b,i)); } sort(d.begin(),d.end()); set<int>::iterator ite; for(ite=s.begin();ite!=s.end();ite++){ int r=Bynary_Search(*ite); if(r>=0){ if(z[0].find(d[r].X)!=z[0].end()) x.push_back(P1(P(d[r].Y,0),P(z[0][d[r].X].X,z[0][d[r].X].Y))); if(z[1].find(d[r].X)!=z[1].end()) x.push_back(P1(P(d[r].Y,1),P(z[1][d[r].X].X,z[1][d[r].X].Y))); } } sort(x.begin(),x.end()); for(int i=0;i<x.size();i++){ int p=x[i].X.Y,px=x[i].Y.X,py=x[i].Y.Y; if(!p){ usac[px]++; if(n!=1){ usac[py+n]++; if(px==py){ usac[n*2]++; if(usac[n*2]==n)cu++; } if(px+py==n-1){ usac[n*2+1]++; if(usac[n*2+1]==n)cu++; } } if(usac[px]==n)cu++; if(usac[py+n]==n)cu++; }else{ nekc[px]++; if(n!=1){ nekc[py+n]++; if(px==py){ nekc[n*2]++; if(nekc[n*2]==n)cn++; } if(px+py==n-1){ nekc[n*2+1]++; if(nekc[n*2+1]==n)cn++; } } if(nekc[px]==n)cn++; if(nekc[py+n]==n)cn++; } if(i+1<x.size()&&x[i].X.X!=x[i+1].X.X){ if(cu>=u)f1=1; if(cn>=v)f2=1; if(f1||f2)break; } } if(cu>=u)f1=1; if(cn>=v)f2=1; if((!f1&&!f2)||(f1&&f2))cout<<"DRAW"<<endl; else if(f1)cout<<"USAGI"<<endl; else cout<<"NEKO"<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; using ld=long double; using P=pair<ll,ll>; #define MOD 1000000007ll #define INF 1000000000ll #define EPS 1e-10 #define FOR(i,n,m) for(ll i=n;i<(ll)m;i++) #define REP(i,n) FOR(i,0,n) #define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;} #define ALL(v) v.begin(),v.end() #define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end()); #define pb push_back ll n,u,v,m; ll max_elem(vector<ll>& card,vector<vector<ll>>& mat, ll idx, char dir) { ll ret=0; if(dir=='h') { REP(i,n) ret=max(ret,card[mat[idx][i]]); } if(dir=='v') { REP(i,n) ret=max(ret,card[mat[i][idx]]); } return ret; } string solve() { cin>>n>>u>>v>>m; vector<vector<ll>> usa_mat(n,vector<ll>(n)); vector<vector<ll>> neko_mat(n,vector<ll>(n)); REP(i,n) REP(j,n) cin>>usa_mat[i][j]; REP(i,n) REP(j,n) cin>>neko_mat[i][j]; vector<ll> card(1000001,INF*INF); REP(i,m) { ll c; cin>>c; card[c]=i; } vector<ll> usa_done(m,0); vector<ll> neko_done(m,0); REP(i,n) { ll tmp=max_elem(card,usa_mat,i,'h'); if(tmp-INF*INF) usa_done[tmp]++; tmp=max_elem(card,usa_mat,i,'v'); if(tmp-INF*INF) usa_done[tmp]++; tmp=max_elem(card,neko_mat,i,'h'); if(tmp-INF*INF) neko_done[tmp]++; tmp=max_elem(card,neko_mat,i,'v'); if(tmp-INF*INF) neko_done[tmp]++; } ll naname1=0,naname2=0,naname3=0,naname4=0; REP(i,n) { naname1=max(naname1,card[usa_mat[i][i]]); naname2=max(naname2,card[usa_mat[i][n-1-i]]); naname3=max(naname3,card[neko_mat[i][i]]); naname4=max(naname4,card[neko_mat[i][n-1-i]]); } if(naname1!=INF*INF) usa_done[naname1]++; if(naname2!=INF*INF) usa_done[naname2]++; if(naname3!=INF*INF) neko_done[naname3]++; if(naname4!=INF*INF) neko_done[naname4]++; ll usa_sum=0,neko_sum=0; REP(i,m) { if(n!=1) { usa_sum+=usa_done[i]; neko_sum+=neko_done[i]; } else { usa_sum+=usa_done[i]/3; neko_sum+=neko_done[i]/3; } if(usa_sum>=u&&neko_sum<v) return "USAGI"; if(usa_sum<u&&neko_sum>=v) return "NEKO"; if(usa_sum>=u&&neko_sum>=v) return "DRAW"; } return "DRAW"; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cout<<solve()<<endl; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <map> using namespace std; using lint = long long; using ldouble = long double; int main() { int N, U[2], M; cin >> N >> U[0] >> U[1] >> M; map<int, int> X[2], Y[2]; for (int i = 0; i < 2; ++i) { for (int x = 0; x < N; ++x) { for (int y = 0; y < N; ++y) { int v; cin >> v; X[i][v] = x; Y[i][v] = y; } } } vector<int> row[2], col[2], diag[2]; for (int i = 0; i < 2; ++i) { row[i].assign(N, 0); col[i].assign(N, 0); diag[i].assign(2, 0); } int total[2] = {0, 0}; for (int q = 0; q < M; ++q) { int v; cin >> v; bool win[2] = {false, false}; for (int i = 0; i < 2; ++i) { if (!X[i].count(v)) continue; if (N == 1) { ++total[i]; } else { if (++row[i][X[i][v]] == N) ++total[i]; if (++col[i][Y[i][v]] == N) ++total[i]; if (X[i][v] - Y[i][v] == 0) { if (++diag[i][0] == N) ++total[i]; } if (X[i][v] + Y[i][v] == N - 1) { if (++diag[i][1] == N) ++total[i]; } } win[i] = (total[i] >= U[i]); } if (win[0] || win[1]) { if (win[0] && win[1]) { cout << "DRAW" << endl; } else { if (win[0]) cout << "USAGI" << endl; if (win[1]) cout << "NEKO" << endl; } return 0; } } cout << "DRAW" << endl; return 0; }
#define DEBUG_ON #define CONDITION true using namespace std;/*{{{*/ #include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <sys/time.h> #include <vector> #define INF (1e9) static const double PI = acos(-1.0); static const double EPS = 1e-10; typedef long long int LL; typedef unsigned long long int ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<char> VC; typedef vector<VC> VVC; typedef vector<string> VS; typedef pair<int, int> PII; typedef complex<double> P; #define FOR(i, b, e) for (typeof(e) i = (b); i != (e); i < (e)? ++i : --i) #define REP(i, n) FOR(i, 0, n) #define IFC(c) if(c) continue; #define IFB(c) if(c) break; #define IFR(c, r) if(c) return r; #define OPOVER(_op, _type) inline bool operator _op (const _type &t) const #define arrsz(a) ( sizeof(a) / sizeof(a[0]) ) #define F first #define S second #define MP(a, b) make_pair(a, b) #define SZ(a) ((LL)a.size()) #define PB(e) push_back(e) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(c,it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define BIT(n) (assert(n < 64), (1ULL << (n))) #define BITOF(n, m) (assert(m < 64), ((ULL)(n) >> (m) & 1)) #define RANGE(a, b, c) ((a) <= (b) && (b) <= (c)) #define PQ priority_queue #define SC static_cast #ifdef DEBUG_ON #define dprt(fmt, ...) if (CONDITION) fprintf(stderr, fmt, ##__VA_ARGS__) #define darr(a) if (CONDITION) copy( (a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ") ); cerr << endl #define darr_range(a, f, t) if (CONDITION) copy( (a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ") ); cerr << endl #define dvec(v) if (CONDITION) copy( ALL(v), ostream_iterator<int>(cerr, " ") ); cerr << endl #define darr2(a, n, m) if (CONDITION) FOR(i, 0, (n)){ darr_range( (a)[i], 0, (m) ); } #define dvec2(v) if (CONDITION) FOR(i, 0, SZ(v)){ dvec( (v)[i] ); } #define WAIT() if (CONDITION) { string _wait_; cerr << "(hit return to continue)" << endl; getline(cin, _wait_); } #define dump(x) if (CONDITION) cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl; #define dumpf() if (CONDITION) cerr << __PRETTY_FUNCTION__ << endl; #define dumpv(x) if (CONDITION) cerr << " [L:" << __LINE__ << "] " << #x << " = "; REP(q, (x).size()) cerr << (x)[q] << " "; cerr << endl; #define where() if (CONDITION) cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__ << "]" << endl; #define show_bits(b, s) if(CONDITION) { REP(i, s) { cerr << BITOF(b, s-1-i); if(i%4 == 3) cerr << ' '; } cerr << endl; } #else #define cerr if(0) cerr #define dprt(fmt, ...) #define darr(a) #define darr_range(a, f, t) #define dvec(v) #define darr2(a, n, m) #define dvec2(v) #define WAIT() #define dump(x) #define dumpf() #define dumpv(x) #define where() #define show_bits(b, s) #endif /* Inline functions */ inline int onbits_count(ULL b) { int c = 0; while(b != 0) { c += (b & 1); b >>= 1; } return c; } inline int bits_count(ULL b) { int c = 0; while(b != 0) { ++c; b >>= 1; } return c; } inline int toInt(string s) { int v; istringstream sin(s);sin>>v;return v; } template<class T> inline string toString(T x) { ostringstream sout;sout<<x;return sout.str(); } inline double now(){ struct timeval tv; gettimeofday(&tv, NULL); return (static_cast<double>(tv.tv_sec) + static_cast<double>(tv.tv_usec) * 1e-6); } inline VS split(string s, char delimiter) { VS v; string t; REP(i, s.length()) { if(s[i] == delimiter) v.PB(t), t = ""; else t += s[i]; } v.PB(t); return v; } /* Tweaks */ template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& d) {return s << "(" << d.first << ", " << d.second << ")";} /* Frequent stuffs */ int n_dir = 4; int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; /* CSS order */ enum direction { UP, RIGHT, DOWN, LEFT }; // int n_dir = 8; // int dx[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy[] = {-1, -1, 0, 1, 1, 1, 0, -1}; // enum direction { // UP, UPRIGHT, RIGHT, DOWNRIGHT, DOWN, DOWNLEFT, LEFT, UPLEFT // } #define FORDIR(d) REP (d, n_dir) /*}}}*/ class Competitor { public: VVI card; map<int, PII> num_to_pos; int quota; int n_bingo; Competitor(int n, int q): quota(q), n_bingo(0) { card = VVI(n, VI(n, 0)); } void write_card(int y, int x, int v) { card[y][x] = v; num_to_pos[v] = MP(y, x); } void punch(int number) { if (!EXIST(num_to_pos, number)) { return; } PII p = num_to_pos[number]; card[p.F][p.S] = 0; bool bingo = true; // vertical REP (i, card.size()) { if (card[i][p.S]) { bingo = false; } } n_bingo += bingo; bingo = true; // horizontal REP (j, card.size()){ if (card[p.F][j]) { bingo = false; } } n_bingo += bingo; // diagonal if (p.F == p.S) { bingo = true; REP (i, card.size()){ if (card[i][i]) { bingo = false; } } n_bingo += bingo; } // diagonal reverse if (p.F == card.size() - 1 - p.S) { bingo = true; REP (i, card.size()) { if (card[i][card.size() - 1 - i]) { bingo = false; } } n_bingo += bingo; } if (card.size() == 1) { n_bingo = n_bingo > 0; } } bool is_winning() { return n_bingo >= quota; } void print_card() { REP (i, card.size()) { REP (j, card.size()) { cerr << card[i][j] << " "; } cerr << endl; } } }; int main() { std::ios_base::sync_with_stdio(false); int n, u, v, m; cin >> n >> u >> v >> m; Competitor usagi(n, u), neko(n, v); vector<Competitor*> competitors; competitors.PB(&usagi); competitors.PB(&neko); REP (c, 2) { REP (i, n) { REP (j, n) { int val; cin >> val; competitors[c]->write_card(i, j, val); } } } bool u_win = false, n_win = false, draw = false; REP (_, m) { int val; cin >> val; IFC(u_win || n_win || draw); REP (c, 2) { competitors[c]->punch(val); } if (usagi.is_winning() && neko.is_winning()) { draw = true; } else if (usagi.is_winning()) { u_win = true; } else if (neko.is_winning()) { n_win = true; } // cerr << "---" << endl; // usagi.print_card(); // cerr << "---" << endl; // neko.print_card(); } if (u_win) { cout << "USAGI" << endl; } else if (n_win) { cout << "NEKO" << endl; } else { cout << "DRAW" << endl; } } // vim: foldmethod=marker
#include<bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> P; signed main(){ int n, u, v, m; cin >> n >> u >> v >> m; vector<P> A(1000001, P{-1, -1}), B; B = A; for ( int i = 0; i < n; i++ ) { for ( int j = 0; j < n; j++ ) { int a; cin >> a; A[a] = P{i, j}; } } for ( int i = 0; i < n; i++ ) { for ( int j = 0; j < n; j++ ) { int a; cin >> a; B[a] = P{i, j}; } } vector<int> num(m); for ( int i = 0; i < m; i++ ) { cin >> num[i]; } vector<int> cnth1(n, 0), cntw1(n, 0), cnth2(n, 0), cntw2(n, 0); int cntl1 = 0, cntr1 = 0, cntl2 = 0, cntr2 = 0; int c1 = 0, c2 = 0; for ( int i = 0; i < m; i++ ) { int a = num[i]; P p1 = A[a], p2 = B[a]; if ( p1.first != -1 ) { if ( ++cnth1[p1.first] == n ) c1++; if ( ++cntw1[p1.second] == n ) c1++; if ( p1.first == p1.second ) { if ( ++cntl1 == n ) c1++; } if ( p1.first + p1.second == n-1 ) { if ( ++cntr1 == n ) c1++; } } if ( p2.first != -1 ) { if ( ++cnth2[p2.first] == n ) c2++; if ( ++cntw2[p2.second] == n ) c2++; if ( p2.first == p2.second ) { if ( ++cntl2 == n ) c2++; } if ( p2.first + p2.second == n-1 ) { if ( ++cntr2 == n ) c2++; } } if ( n == 1 ) { if ( u > 1 && v > 1 ) { break; } else if ( u == 1 && v > 1 ) { if ( c1 >= u ) { cout << "USAGI" << endl; return 0; } } else if ( u > 1 && v == 1 ) { cout << "NEKO" << endl; return 0; } else { if ( c1 >= u && c2 >= v ) { break; } else if ( c1 >= u ) { cout << "USAGI" << endl; return 0; } else if ( c2 >= v ) { cout << "NEKO" << endl; return 0; } } } else { if ( c1 >= u && c2 >= v ) { break; } else if ( c1 >= u ) { cout << "USAGI" << endl; return 0; } else if ( c2 >= v ) { cout << "NEKO" << endl; return 0; } } } cout << "DRAW" << endl; return 0; }
#include <map> #include <iostream> #define REP(i,n) for (int i=0;i<(n);i++) using namespace std; typedef pair<int, int> P; int main(){ int n,u,v,m,k; cin >> n >> u >> v >> m; if(n==1){ int usagi_c=0,neko_c=0; int usagi_one,neko_one; cin>>usagi_one>>neko_one; int tmp; REP(i,m){ cin >> tmp; if(tmp==usagi_one)usagi_c++; if(tmp==neko_one)neko_c++; } if(u==usagi_c&&v==neko_c)cout << "DRAW"<<endl; else if(u==usagi_c)cout << "USAGI"<<endl; else if(v==neko_c)cout << "NEKO" << endl; else cout << "DRAW" << endl; }else{ int usagi_x[n]; fill(usagi_x,usagi_x+n,0); int usagi_y[n]; fill(usagi_y,usagi_y+n,0); int usagi_xy=0,usagi_yx=0; int neko_x[n]; fill(neko_x,neko_x+n,0); int neko_y[n]; fill(neko_y,neko_y+n,0); int neko_xy=0,neko_yx=0; int usagi_n=0; int neko_n=0; map<int,P> usagi, neko; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin >> k; usagi[k]=P(i,j); } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin >> k; neko[k]=P(i,j); } } for(int i=0;i<m;i++){ bool neko_b=false,usagi_b=false; cin >> k; auto it = usagi.find(k); if(it!=usagi.end()){ int x=it->second.first,y=it->second.second; usagi.erase(k); if(++usagi_x[x]==n) usagi_n++; if(++usagi_y[y]==n) usagi_n++; if(x==y){ if(++usagi_xy==n) usagi_n++; } if(x+y==n-1){ if(++usagi_yx==n) usagi_n++; } if(usagi_n>=u) usagi_b=true; } it = neko.find(k); if(it!=neko.end()){ int x=it->second.first,y=it->second.second; neko.erase(k); if(++neko_x[x]==n) neko_n++; if(++neko_y[y]==n) neko_n++; if(x==y){ if(++neko_xy==n) neko_n++; } if(x+y==n-1){ if(++neko_yx==n) neko_n++; } if(neko_n>=v) neko_b=true; } if(neko_b&&usagi_b){ cout<<"DRAW"<<endl; return 0; }else if(neko_b){ cout<<"NEKO"<<endl; return 0; }else if(usagi_b){ cout<<"USAGI"<<endl; return 0; } } cout<<"DRAW"<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int cnt[2][2][555]; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int n,u,v,m; cin>>n>>u>>v>>m; map<int,pair<int,int>> neko,usa; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int a; cin>>a; usa[a]=make_pair(i,j); } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int a;cin>>a; neko[a]=make_pair(i,j); } } int c; if(n==1){ if(u>1 && v>1){ cout<<"DRAW"<<endl; return 0; } int cat=0,rabi=0; for(int i=0;i<m;i++){ cin>>c; if(usa.count(c)){ rabi++; } if(neko.count(c)){ cat++; } if(cat>=v && rabi>=u){ cout<<"DRAW"<<endl; return 0; } if(cat>=v){ cout<<"NEKO"<<endl; return 0; } if(rabi>=u){ cout<<"USAGI"<<endl; return 0; } } } int naname[2][2]={}; int line[2]={}; for(int i=0;i<m;i++){ cin>>c; if(usa.count(c)){ int x=usa[c].first, y=usa[c].second; cnt[0][0][x]++; cnt[0][1][y]++; if(cnt[0][0][x]==n){ line[0]++; } if(cnt[0][1][y]==n){ line[0]++; } if(x==y){ naname[0][0]++; if(naname[0][0]==n) line[0]++; } if(x+y==n-1){ naname[0][1]++; if(naname[0][1]==n) line[0]++; } } if(neko.count(c)){ int x=neko[c].first, y=neko[c].second; cnt[1][0][x]++; cnt[1][1][y]++; if(cnt[1][0][x]==n){ line[1]++; } if(cnt[1][1][y]==n){ line[1]++; } if(x==y){ naname[1][0]++; if(naname[1][0]==n) line[1]++; } if(x+y==n-1){ naname[1][1]++; if(naname[1][1]==n) line[1]++; } } //cerr<<i<<" "<<line[0]<<" "<<line[1]<<endl; if(line[0]>=u && line[1]>=v){ cout<<"DRAW"<<endl; return 0; } if(line[0]>=u){ cout<<"USAGI"<<endl; return 0; } if(line[1]>=v){ cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; }
#include <bits/stdc++.h> #define N 1000001 using namespace std; typedef pair <int,int> P; int n,u,v,m,num[N]; P U[N],V[N]; void in(P a[]){ for(int i=1;i<=n;i++) for(int j=1,b;j<=n;j++) cin>>b,a[b]=P(i,j); } int game(P A[],int B){ int ta[501]={},yo[501]={},X[2]={},cnt=n!=1? 0:-3; for(int i=0;i<m;i++){ int y=A[num[i]].first,x=A[num[i]].second; if(x==0)continue; X[0]+=(x==y),X[1]+=(x+y==n+1); if(X[0]==n) X[0]=-1e9,cnt++; if(X[1]==n) X[1]=-1e9,cnt++; cnt+=(++ta[y]==n)+(++yo[x]==n); if(cnt>=B)return i; } return m; } int main(){ cin>>n>>u>>v>>m; in(U),in(V); for(int i=0;i<m;i++) cin>>num[i]; int Uscore=game(U,u); int Vscore=game(V,v); if(Uscore<Vscore) cout <<"USAGI"<<endl; else if(Uscore>Vscore)cout <<"NEKO"<<endl; else cout<<"DRAW"<<endl; return 0; }
#include <sstream> #include <string> #include <vector> #include <map> #include <algorithm> #include <iostream> #include <utility> #include <set> #include <cctype> #include <queue> #include <stack> #include <cstdio> #include <cstdlib> #include <cmath> #include <climits> using namespace std; #define INF 100000000 #define MAXM 1000001 #define MAXN 512 typedef pair<int, int> P; typedef long long ll; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; int n, u, v, m; vector<P> usagi[MAXM]; vector<P> neko[MAXM]; int usabingo_tate[MAXN]; int usabingo_yoko[MAXN]; int usabingo_naname[2]; int nekobingo_tate[MAXN]; int nekobingo_yoko[MAXN]; int nekobingo_naname[2]; int usabingo = 0; int nekobingo = 0; int main(void) { cin >> n >> u >> v >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int c; cin >> c; usagi[c].push_back(make_pair(i, j)); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int c; cin >> c; neko[c].push_back(make_pair(i, j)); } } for (int i = 0; i < m; i++) { int num; cin >> num; // usagi for (int j = 0; j < usagi[num].size(); j++) { int y = usagi[num][j].first; int x = usagi[num][j].second; if (x == y) { if (++usabingo_naname[0] == n) { usabingo++; if (n == 1) usabingo = min(usabingo , n); } } if ((n-1) - x == y) { if (++usabingo_naname[1] == n) { usabingo++; if (n == 1) usabingo = min(usabingo , n); } } if (++usabingo_tate[x] == n) { usabingo++; if (n == 1) usabingo = max(usabingo , n); } if (++usabingo_yoko[y] == n) { usabingo++; if (n == 1) usabingo = min(usabingo , n); } } // neko for (int j = 0; j < neko[num].size(); j++) { int y = neko[num][j].first; int x = neko[num][j].second; if (x == y) { if (++nekobingo_naname[0] == n) { nekobingo++; if (n == 1) nekobingo = min(nekobingo , n); } } if ((n-1) - x == y) { if (++nekobingo_naname[1] == n) { nekobingo++; if (n == 1) nekobingo = min(nekobingo , n); } } if (++nekobingo_tate[x] == n) { nekobingo++; if (n == 1) nekobingo = min(nekobingo , n); } if (++nekobingo_yoko[y] == n) { nekobingo++; if (n == 1) nekobingo = min(nekobingo , n); } } // cout << "usabingo " << usabingo << endl; // cout << "nekobingo " << nekobingo << endl; if (usabingo >= u && nekobingo < v) { cout << "USAGI" << endl; return 0; } else if (usabingo < u && nekobingo >= v) { cout << "NEKO" << endl; return 0; } else if (usabingo >= u && nekobingo >= v) { cout << "DRAW" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MAX 1000001 int ru[MAX],cu[MAX]; int rv[MAX],cv[MAX]; int a[MAX],b[MAX],c,d; int e[MAX],f[MAX],g,h; int main(){ int N,u,v,m,in; cin >> N >> u >> v >> m; for(int i = 0 ; i < MAX ; i++){ ru[i] = cu[i] = rv[i] = cv[i] = -1; a[i] = b[i] = N; e[i] = f[i] = N; } c = d = g = h = N; for(int i = 0 ; i < N ; i++){ for(int j = 0 ; j < N ; j++){ cin >> in; ru[in] = i; cu[in] = j; } } for(int i = 0 ; i < N ; i++){ for(int j = 0 ; j < N ; j++){ cin >> in; rv[in] = i; cv[in] = j; } } bool usagi = false,neko = false; int x; while(m--){ cin >> x; if(N == 1){ if(ru[x] != -1){ u--; } if(rv[x] != -1){ v--; } if(u == 0) usagi = true; if(v == 0) neko = true; if(usagi || neko) break; continue; } if(ru[x] != -1){ a[ru[x]]--; b[cu[x]]--; if(ru[x] == cu[x]){ if( N/2 == ru[x] && (N & 1) ){ c--; d--; }else{ c--; } if(c == 0){ c = -1; u--; } if(d == 0){ d = -1; u--; } } else if(ru[x]+cu[x] == N-1){ d--; if(d == 0){ d = -1; u--; } } if(a[ru[x]] == 0){ ru[x] = -1; u--; } if(b[cu[x]] == 0){ cu[x] = -1; u--; } } if(rv[x] != -1){ e[rv[x]]--; f[cv[x]]--; if(rv[x] == cv[x]){ if(N/2 == rv[x] && (N&1) ){ g--; h--; }else{ g--; } if(g == 0){ g = -1; v--; } if(h == 0){ h = -1; v--; } } else if(rv[x]+cv[x] == N-1){ h--; if(h == 0){ h = -1; v--; } } if(e[rv[x]] == 0){ rv[x] = -1; v--; } if(f[cv[x]] == 0){ cv[x] = -1; v--; } } if(u <= 0) usagi = true; if(v <= 0) neko = true; if(usagi || neko){ break; } } while( cin >> x ){} if((usagi && neko) || (!usagi && !neko)){ cout << "DRAW" << endl; }else if(usagi){ cout << "USAGI" << endl; }else{ cout << "NEKO" << endl; } return 0; }
#include"bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; #define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++) #define REP(i,n) FOR((i),0,(n)) #define WAITING(str) int str;std::cin>>str; #define DEBUGING(str) cout<< #str << " " str<<endl constexpr int INF = (1 << 30); constexpr ll INFL = (1ll << 60); constexpr ll MOD = 1000000007;// 10^9+7 int n, u, v, m; vector<vector<int>> usa, neko; vector<int> card; void paint(vector<vector<int>>& tile, int lim) { set<int> cand; REP(i, lim) cand.insert(card[i]); REP(i, n)REP(j, n) { int num = tile[i][j]; if (cand.find(num) == cand.end()) { tile[i][j] = 0; } } } int judge(vector<vector<int>> tile, int lim) { paint(tile, lim); int res = 0; // ud REP(i, n) { REP(j, n)if (tile[i][j] == 0)goto end; res++; end:; } // lr REP(j, n) { REP(i, n)if (tile[i][j] == 0)goto end2; res++; end2:; } // slash REP(i, n) if (tile[i][i] == 0)goto end3; res++; end3:; REP(i, n)if (tile[i][n - 1 - i] == 0)goto end4; res++; end4:; return res; } void single() { int uidx = find(card.begin(), card.end(), usa[0][0]) - card.begin(); int nidx = find(card.begin(), card.end(), neko[0][0]) - card.begin(); if (u == 1 && v == 1) { if (uidx == nidx)cout << "DRAW" << endl; else cout << (uidx < nidx ? "USAGI" : "NEKO") << endl; } else if (u == 1) { cout << (uidx < m ? "USAGI" : "DRAW") << endl; } else if (v == 1) { cout << (uidx < m ? "NEKO" : "DRAW") << endl; } else { cout << "DRAW" << endl; } } int main() { cin >> n >> u >> v >> m; usa.resize(n, vector<int>(n)); neko.resize(n, vector<int>(n)); card.resize(m); REP(i, n) REP(j, n)cin >> usa[i][j]; REP(i, n) REP(j, n)cin >> neko[i][j]; REP(i, m)cin >> card[i]; if (n == 1) { single(); return 0; } int l = 0, r = m; while (r - l > 1) { int mid = (l + r) / 2; bool res1 = judge(usa, mid) >= u; bool res2 = judge(neko, mid) >= v; if (res1 && res2)r = mid; else if (!res1 && !res2) l = mid; else { cout << (res1 ? "USAGI" : "NEKO") << endl; return 0; } } bool res1 = judge(usa, r) >= u; bool res2 = judge(neko, r) >= v; if (res1 == res2)cout << "DRAW" << endl; else cout << (res1 ? "USAGI" : "NEKO") << endl; return 0; }
#include <iostream> #include <string> #include <map> #include <vector> using namespace std; int main(){ int n, u, v, m; cin >> n >> u >> v >> m; map<int, pair<int,int> > U, N; int t; if(n == 1){ if(u > 1){ u += 5; } if(v > 1){ v += 5; } } for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ cin >> t; U[t] = make_pair(i+1,j+1); } } for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ cin >> t; N[t] = make_pair(i+1,j+1); } } int T[m]; vector< vector<int> > U_(2,vector<int>(n+1,n)), N_(2,vector<int>(n+1,n)); for(int i = 0; i < m; ++i) cin >> T[i]; for(int i = 0; i < m; ++i){ int k = T[i], s = U[k].first, t = U[k].second; if(s&&t){ --U_[0][s]; --U_[1][t]; if(s == t) --U_[0][0]; if(s + t == n+1) --U_[1][0]; if(!U_[0][s]){ --u; --U_[0][s]; } if(!U_[1][t]){ --u; --U_[1][t]; } if(!U_[0][0]){ --u; --U_[0][0]; } if(!U_[1][0]){ --u; --U_[1][0]; } } s = N[k].first, t = N[k].second; if(s&&t){ --N_[0][s]; --N_[1][t]; if(s == t) --N_[0][0]; if(s + t == n+1) --N_[1][0]; if(!N_[0][s]){ --v; --N_[0][s]; } if(!N_[1][t]){ --v; --N_[1][t]; } if(!N_[0][0]){ --v; --N_[0][0]; } if(!N_[1][0]){ --v; --N_[1][0]; } } if(u <= 0 && v <= 0){ cout << "DRAW" << endl; return 0; }else if(u <= 0){ cout << "USAGI" << endl; return 0; }else if(v <= 0){ cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef DEBUG #include "inc/debug.hpp" #else #define debug(...) 42 #endif int score[2]; bool mark[2][500][500]; int dx[4] = {1, 0, 1, 1}; int dy[4] = {0, 1, 1, -1}; string solve() { int n, u, v, m; cin >> n >> u >> v >> m; map<int, vector<pair<int,int>>> p[2]; for (int t=0; t<2; ++t) { for (int i=0; i<n; ++i) { for (int j=0; j<n; ++j) { int a; cin >> a; p[t][a].emplace_back(i, j); } } } for (int i=0; i<m; ++i) { int a; cin >> a; for (int j=0; j<2; ++j) { for (auto& pp: p[j][a]) { int y, x; tie(y, x) = pp; mark[j][y][x] = true; if (n == 1) { score[j] ++; continue; } for (int k=0; k<4; ++k) { int len = -1, ty = y, tx = x; while (0 <= ty && ty < n && 0 <= tx && tx < n && mark[j][ty][tx]) { ty += dy[k]; tx += dx[k]; len ++; } ty = y, tx = x; while (0 <= ty && ty < n && 0 <= tx && tx < n && mark[j][ty][tx]) { ty -= dy[k]; tx -= dx[k]; len ++; } if (len == n) score[j] ++; } } } if (u <= score[0] && v <= score[1]) return "DRAW"; if (u <= score[0]) return "USAGI"; if (v <= score[1]) return "NEKO"; } return "DRAW"; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << solve() << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int N, U[2], M, A[2][500][500]; bool flag[2][500][500] = {{}}; map< int, vector< tuple< int, int, int > > > memo; int main() { scanf("%d %d %d %d", &N, &U[0], &U[1], &M); for(int k = 0; k < 2; k++) { for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { scanf("%d", &A[k][i][j]); memo[A[k][i][j]].emplace_back(k, i, j); } } } while(M--) { int num; scanf("%d", &num); for(auto& d : memo[num]) { int k, i, j; tie(k, i, j) = d; flag[k][i][j] = true; bool f1 = true, f2 = true; bool f3 = i == j; bool f4 = j == N - i - 1; for(int l = 0; l < N; l++) { f1 &= flag[k][i][l]; f2 &= flag[k][l][j]; f3 &= flag[k][l][l]; f4 &= flag[k][l][N - l - 1]; } U[k] -= f1; if(N > 1) { U[k] -= f2; U[k] -= f3; U[k] -= f4; } } if(U[0] <= 0 || U[1] <= 0) { if(U[0] <= 0 && U[1] <= 0) break; puts(U[1] <= 0 ? "NEKO" : "USAGI"); exit(0); } } puts("DRAW"); }
#include <algorithm> #include <cmath> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <cassert> #include <functional> using namespace std; #define LOG(...) printf(__VA_ARGS__) //#define LOG(...) #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define REP(i,n) for(int i=0;i<(int)(n);++i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) #define RSORT(c) sort((c).rbegin(),(c).rend()) #define CLR(a) memset((a), 0 ,sizeof(a)) typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 }; struct UnionFind { vector<int> v; UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; } int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); } void unite(int x, int y) { v[find(x)] = find(y); } }; int main() { int n, u, v, m; cin >> n >> u >> v >> m; map<int, pair<int, int>> bingo_u; map<int, pair<int, int>> bingo_v; REP(i,n) REP(j, n){ int num; cin >> num; bingo_u[num] = pair<int, int>(i,j); } REP(i, n) REP(j, n){ int num; cin >> num; bingo_v[num] = pair<int, int>(i, j); } queue<int> tyusen; REP(i, m){ int num; cin >> num; tyusen.push(num); } vector<int> usa_h(n,0); vector<int> usa_v(n,0); int usa_naname[2] = {0}; vector<int> nek_h(n,0); vector<int> nek_v(n,0); int nek_naname[2] = {0}; while (!tyusen.empty()){ int q = tyusen.front(); tyusen.pop(); if (bingo_u.find(q) != bingo_u.end()){ if (n == 1) u--; else{ usa_h[bingo_u[q].first]++; if (usa_h[bingo_u[q].first] == n) u--; usa_v[bingo_u[q].second]++; if (usa_v[bingo_u[q].second] == n) u--; if (bingo_u[q].first == bingo_u[q].second){ usa_naname[0]++; if (usa_naname[0] == n) u--; } if (bingo_u[q].first + bingo_u[q].second == n - 1){ usa_naname[1]++; if (usa_naname[1] == n) u--; } } } if (bingo_v.find(q) != bingo_v.end()){ if (n == 1) v--; else{ nek_h[bingo_v[q].first]++; if (nek_h[bingo_v[q].first] == n) v--; nek_v[bingo_v[q].second]++; if (nek_v[bingo_v[q].second] == n) v--; if (bingo_v[q].first == bingo_v[q].second){ nek_naname[0]++; if (nek_naname[0] == n) v--; } if (bingo_v[q].first + bingo_v[q].second == n - 1){ nek_naname[1]++; if (nek_naname[1] == n) v--; } } } if (u <= 0 && v <= 0){ cout << "DRAW" << endl; return 0; } else if (u <= 0){ cout << "USAGI" << endl; return 0; } else if (v<=0){ cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int n, usa_point, neko_point, m; cin >> n >> usa_point >> neko_point >> m; map<int, pair<int, int> > usa_map; map<int, pair<int, int> > neko_map; vector<vector<bool> > usa_check(n, vector<bool> (n, false)); vector<vector<bool> > neko_check(n, vector<bool> (n, false)); for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ int input; cin >> input; usa_map[input] = {i, j}; } } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ int input; cin >> input; neko_map[input] = {i, j}; } } bool flag = false; for(int i = 0; i < m; i++){ int num; cin >> num; if(flag) continue; //うさぎさん if(usa_map.find(num) != usa_map.end()){ int usa_i = usa_map[num].first; int usa_j = usa_map[num].second; //印をつける usa_check[usa_i][usa_j] = true; //横 bool ok = true; for(int j = 0; j < n; j++){ if(!usa_check[usa_i][j]){ ok = false; break; } } if(n != 1 && ok) usa_point--; //縦 ok = true; for(int i = 0; i < n; i++){ if(!usa_check[i][usa_j]){ ok = false; break; } } if(n != 1 && ok) usa_point--; //ななめ if(usa_i == usa_j){ ok = true; for(int k = 0; k < n; k++){ if(!usa_check[k][k]){ ok = false; break; } } if(n != 1 && ok) usa_point--; } //斜め if(usa_i + usa_j == n - 1){ ok = true; for(int k = 0; k < n; k++){ if(!usa_check[k][n - 1 - k]){ ok = false; break; } } if(ok) usa_point--; } } //猫さん if(neko_map.find(num) != neko_map.end()){ int neko_i = neko_map[num].first; int neko_j = neko_map[num].second; //印をつける neko_check[neko_i][neko_j] = true; //横 bool ok = true; for(int j = 0; j < n; j++){ if(!neko_check[neko_i][j]){ ok = false; break; } } if(n != 1 && ok) neko_point--; //縦 ok = true; for(int i = 0; i < n; i++){ if(!neko_check[i][neko_j]){ ok = false; break; } } if(n != 1 && ok) neko_point--; //ななめ if(neko_i == neko_j){ ok = true; for(int k = 0; k < n; k++){ if(!neko_check[k][k]){ ok = false; break; } } if(n != 1 && ok) neko_point--; } //斜め if(neko_i + neko_j == n - 1){ ok = true; for(int k = 0; k < n; k++){ if(!neko_check[k][n - 1 - k]){ ok = false; break; } } if(ok) neko_point--; } } //cout << neko_point << " " << usa_point << endl; if(neko_point <= 0 && usa_point > 0){ cout << "NEKO" << endl; flag = true; }else if(neko_point > 0 && usa_point <= 0){ cout << "USAGI" << endl; flag = true; }else if(neko_point <= 0 && usa_point <= 0){ cout << "DRAW" << endl; flag = true; } } if(!flag) cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr) #define all(x) (x).begin(),(x).end() #define pb push_back #define fi first #define se second typedef pair<int,int> pi; int check(const vector<vector<int>> &z) { int Z=z.size(); if(Z==1) return z[0][0]; int ret=0; rep(i,Z) { bool ok=true; rep(j,Z) { if(z[i][j]==0) ok=false; } if(ok) ++ret; } rep(i,Z) { bool ok=true; rep(j,Z) { if(z[j][i]==0) ok=false; } if(ok) ++ret; } bool ok=true; rep(i,Z) { if(z[i][i]==0) ok=false; } if(ok) ++ret; ok=true; rep(i,Z) { if(z[i][Z-1-i]==0) ok=false; } if(ok) ++ret; return ret; } int main() { int n,m,win[2]; int num[100000]; map<int,pi> f[2]; scanf(" %d %d %d %d", &n, &win[0], &win[1], &m); rep(i,2)rep(j,n)rep(k,n) { int c; scanf(" %d", &c); f[i][c] = pi(j,k); } rep(i,m) scanf(" %d", &num[i]); int l=-1,r=m; while(r-l>1) { int mid=(l+r)/2; vector<vector<int>> v[2]; rep(i,2) v[i]=vector<vector<int>>(n,vector<int>(n,0)); rep(i,mid+1) { rep(j,2)if(f[j].find(num[i]) != f[j].end()) { pi p=f[j][num[i]]; v[j][p.fi][p.se]=1; } } int a[2]; rep(i,2) a[i]=check(v[i]); if(win[0]<=a[0] || win[1]<=a[1]) r=mid; else l=mid; } string ans="DRAW"; if(r<m) { vector<vector<int>> v[2]; rep(i,2) v[i]=vector<vector<int>>(n,vector<int>(n,0)); rep(i,r+1) { rep(j,2)if(f[j].find(num[i]) != f[j].end()) { pi p=f[j][num[i]]; v[j][p.fi][p.se]=1; } } int a[2]; rep(i,2) a[i]=check(v[i]); if(win[0]<=a[0] && win[1]<=a[1]) ans="DRAW"; else { if(win[0]<=a[0]) ans="USAGI"; if(win[1]<=a[1]) ans="NEKO"; } } cout << ans << endl; return 0; }
// // main.cpp // // g++ -std=c++14 main.cpp // //#include "main.hpp" #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <math.h> using namespace std; typedef long long ll; int main(void){ int n, u, v, m; cin >> n >> u >> v >> m; vector<int> usa(1000005, -1), neko(1000005, -1); int usa_tate[1000] = {}, usa_yoko[1000] = {}, usa_nana[2] = {}; int neko_tate[1000] = {}, neko_yoko[1000] = {}, neko_nana[2] = {}; for (int i = 0; i < n * n; i++) { int b; cin >> b; usa[b] = i; } for (int i = 0; i < n * n; i++) { int b; cin >> b; neko[b] = i; } int usa_p = 0, neko_p = 0; for (int i = 0; i < m; i++) { int k; cin >> k; if (usa[k] != -1) { usa_tate[usa[k] / n]++; if (usa_tate[usa[k] / n] == n) usa_p++; usa_yoko[usa[k] % n]++; if (usa_yoko[usa[k] % n] == n) usa_p++; if (usa[k] % n == usa[k] / n) { usa_nana[0]++; if (usa_nana[0] == n) usa_p++; } if (usa[k] % n == n - 1 - usa[k] / n) { usa_nana[1]++; if (usa_nana[1] == n) usa_p++; } } /* for (int i = 0; i < n; i++) cout << usa_tate[i] << " "; for (int i = 0; i < n; i++) cout << usa_yoko[i] << " "; cout << usa_nana[0] << " " << usa_nana[1] << endl;*/ if (neko[k] != -1) { neko_tate[neko[k] / n]++; if (neko_tate[neko[k] / n] == n) neko_p++; neko_yoko[neko[k] % n]++; if (neko_yoko[neko[k] % n] == n) neko_p++; if (neko[k] % n == neko[k] / n) { neko_nana[0]++; if (neko_nana[0] == n) neko_p++; } if (neko[k] % n == n - 1 - neko[k] / n) { neko_nana[1]++; if (neko_nana[1] == n) neko_p++; } } /* for (int i = 0; i < n; i++) cout << neko_tate[i] << " "; for (int i = 0; i < n; i++) cout << neko_yoko[i] << " "; cout << neko_nana[0] << " " << neko_nana[1] << endl; cout << usa_p << " " << neko_p << endl;*/ if (n >= 2) { if (usa_p >= u && neko_p >= v) { cout << "DRAW" << endl; return 0; } else if (usa_p >= u) { cout << "USAGI" << endl; return 0; } else if (neko_p >= v) { cout << "NEKO" << endl; return 0; } } else { if (usa_p/3 >= u && neko_p/3 >= v) { cout << "DRAW" << endl; return 0; } else if (usa_p/3 >= u) { cout << "USAGI" << endl; return 0; } else if (neko_p/3 >= v) { cout << "NEKO" << endl; return 0; } } } cout << "DRAW" << endl; } /* g++ -std=c++14 main2.cpp */
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" #include "numeric" #include "cassert" #include "ctime" using namespace std; constexpr long long int MOD = 1000000007; //constexpr int MOD = 1000000007; //constexpr int MOD = 998244353; //constexpr long long int MOD = 998244353; constexpr double EPS = 1e-12; //int N, M, K, T, H, W, L, R; long long int N, M, K, T, H, W, L, R; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> L >> R >> K; vector<int>ay(1000001, -1); vector<int>ax(1000001, -1); vector<int>by(1000001, -1); vector<int>bx(1000001, -1); vector<int>axnum(N); vector<int>aynum(N); vector<int>bxnum(N); vector<int>bynum(N); int aldnum = 0; int alunum = 0; int bldnum = 0; int blunum = 0; if (N == 1) { L += 3, R += 3; } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> M; ay[M] = i, ax[M] = j; } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cin >> M; by[M] = i, bx[M] = j; } } int a = 0, b = 0; while (K--) { cin >> M; if (ay[M] != -1) { aynum[ay[M]]++; if (aynum[ay[M]] == N)a++; axnum[ax[M]]++; if (axnum[ax[M]] == N)a++; if (ay[M] == ax[M]) { aldnum++; if (aldnum == N)a++; } if (ay[M] + ax[M] == N - 1) { alunum++; if (alunum == N)a++; } } if (by[M] != -1) { bynum[by[M]]++; if (bynum[by[M]] == N)b++; bxnum[bx[M]]++; if (bxnum[bx[M]] == N)b++; if (by[M] == bx[M]) { bldnum++; if (bldnum == N)b++; } if (by[M] + bx[M] == N - 1) { blunum++; if (blunum == N)b++; } } if (a >= L && b >= R) { cout << "DRAW" << endl; return 0; } if (a >= L) { cout << "USAGI" << endl; return 0; } if (b >= R) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; }
#include <bits/stdc++.h> using namespace std; //#define int long long #define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i)) #define rep(i,n) reps(i,0,n) #define rept(i,n) rep(i,(n)+1) #define repst(i,s,n) reps(i,s,(n)+1) #define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i)) #define repr(i,n) reprt(i,n,0) #define each(itr,v) for(auto &(itr):(v)) #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() #define pb push_back #define mp make_pair #define fi first #define se second #define tmax(x,y,z) max(x,max(y,z)) #define tmin(x,y,z) min(x,min(y,z)) #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) #define ln '\n' #define bln(i,n) (((i)==(n)-1)?'\n':' ') #define dbg(x) cout<<#x" = "<<(x)<<ln<<flush #define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}} #define zero(a) memset(a,0,sizeof(a)) #define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end()) typedef long double ld; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<string> vst; typedef vector<bool> vb; typedef vector<ld> vld; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vector<int> > mat; const ll inf = (ll)1e9+10; const ll linf = (ll)1e18+10; const ll mod = (ll)(1e9+7); const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1}; const double eps = 1e-10; ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m; assert(b>=0); for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;} ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a,ll b) {return a*b/gcd(a,b);} struct oreno_initializer { oreno_initializer() { cin.tie(0); ios::sync_with_stdio(0); } } oreno_initializer; // ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥… // .。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+ // ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・ // うさぎとねこを0と1にして配列とかメソッドをまとめるべきだった クソ実装 int n, u, v, m, r[505][505], c[505][505], t, rh[505], rw[505], rdl, rdr, ch[505], cw[505], cdl, cdr; map<int,pii> rp, cp; bool rwin() { int x = rp[t].fi, y = rp[t].se; if (x==0) return 0; if (n==1) return u==1; u -= (++rh[x]==n) + (++rw[y]==n); if (x==y) u -= (++rdl==n); if (x+y==n+1) u -= (++rdr==n); return u<=0; } bool cwin() { int x = cp[t].fi, y = cp[t].se; if (x==0) return 0; if (n==1) return v==1; v -= (++ch[x]==n) + (++cw[y]==n); if (x==y) v -= (++cdl==n); if (x+y==n+1) v -= (++cdr==n); return v<=0; } signed main() { cin >> n >> u >> v >> m; repst(i,1,n) repst(j,1,n) { cin >> r[i][j]; rp[r[i][j]] = {i,j}; } repst(i,1,n) repst(j,1,n) { cin >> c[i][j]; cp[c[i][j]] = {i,j}; } rep(i,m) { cin >> t; bool a = rwin(), b = cwin(); if (!a && !b) continue; else { if (a && b) cout << "DRAW" << ln; else if (a) cout << "USAGI" << ln; else cout << "NEKO" << ln; return 0; } } cout << "DRAW" << ln; }
#include <cstdio> #include <algorithm> #include <vector> #include <map> struct Bingo { std::map<int, std::pair<int, int>> card; std::vector<int> row, col, diag; int num_bingo, size; Bingo(int n): row(n), col(n), diag(2), num_bingo(0), size(n) {} void set(int r, int c, int x) { card[x] = std::make_pair(r, c); } int push(int x) { auto it=card.find(x); if (it == card.end()) return num_bingo; const std::pair<int, int> &p=it->second; if (++row[p.first] == size) ++num_bingo; if (++col[p.second] == size) ++num_bingo; if (p.first == p.second) if (++diag[0] == size) ++num_bingo; if (p.first + p.second + 1 == size) if (++diag[1] == size) ++num_bingo; if (num_bingo && size == 1) return (num_bingo = 1); return num_bingo; } }; int main() { int n, u, v, m; scanf("%d %d %d %d", &n, &u, &v, &m); Bingo usagi(n), neko(n); for (int r=0; r<n; ++r) for (int c=0; c<n; ++c) { int k; scanf("%d", &k); usagi.set(r, c, k); } for (int r=0; r<n; ++r) for (int c=0; c<n; ++c) { int k; scanf("%d", &k); neko.set(r, c, k); } for (int i=0; i<m; ++i) { int k; scanf("%d", &k); int usagi_line=usagi.push(k); int neko_line=neko.push(k); bool usagi_bingo=(usagi_line>=u); bool neko_bingo=(neko_line>=v); if (usagi_bingo && neko_bingo) { return !printf("DRAW\n"); } else if (usagi_bingo) { return !printf("USAGI\n"); } else if (neko_bingo) { return !printf("NEKO\n"); } } printf("DRAW\n"); return 0; }
#include <iostream> #include <vector> #include <set> #include <map> #include <string> #include <stack> #include <functional> #include <queue> #include <tuple> #include <cstring> using namespace std; #define rep(i,n) for(int i = 0;i < n;i++) #define each(i,n) for(auto i : n) #define all(n) n.begin(),n.end() #define clr(n) memset(n,0,sizeof(n)) #define mclr(n) memset(n,-1,sizeof(n)) int main() { int n, a, b, m; cin >> n >> a >> b >> m; typedef pair<int, int> P; map<int, P> ap, bp; rep(y, n)rep(x, n) { int t; cin >> t; ap[t] = P(y, x); } rep(y, n)rep(x, n) { int t; cin >> t; bp[t] = P(y, x); } map<int, int> ax, ay, axy, ayx; map<int, int> bx, by, bxy, byx; bool aw = 0, bw = 0; int ac = 0, bc = 0; rep(i, m) { int t; cin >> t; if (n == 1) { ac += ap.count(t); bc += bp.count(t); } else { if (ap.count(t)) { int y = ap[t].first, x = ap[t].second; ax[x]++; ay[y]++; ayx[y - x]++; axy[x + y]++; if (ax[x] >= n) { ac++; } if (ay[y] >= n) { ac++; } if (ayx[y - x] >= n) { ac++; } if (axy[x + y] >= n) { ac++; } } if (bp.count(t)) { int y = bp[t].first, x = bp[t].second; bx[x]++; by[y]++; byx[y - x]++; bxy[x + y]++; if (bx[x] >= n) { bc++; } if (by[y] >= n) { bc++; } if (byx[y - x] >= n) { bc++; } if (bxy[x + y] >= n) { bc++; } } } if (ac >= a)aw = 1; if (bc >= b)bw = 1; if (aw && bw) { cout << "DRAW" << endl; return 0; } if (aw) { cout << "USAGI" << endl; return 0; } if (bw) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> #include <math.h> #include <set> #include <map> #include <string> #include <stack> #include <queue> #include <iomanip> #include <numeric> #include <tuple> #include <bitset> #include <complex> #include <unistd.h> #include <cassert> #include <cctype> #include <random> #define _USE_MATH_DEFINES #define _GLIBCXX_DEBUG using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> plglg; typedef pair<double, ll> pdlg; typedef tuple<int, int, int> tiii; typedef tuple<ll, ll, ll> tlglglg; typedef tuple<double, double, double> tddd; typedef complex<double> xy_t; #define REP(i, x, y) for(ll i = x; i < y; i++) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; double pi = 3.141592653589793; ll mod = 1000000007; int intmax = 2147483647; int intmin = -2147483648; ll llmax = 9223372036854775807; ll llmin = -9223372036854775807; int iinf = intmax / 8; ll inf = llmax / 8; double eps = 1e-11; plglg usa[1000010]; plglg neko[1000010]; ll usatate[510], usayoko[510], nekotate[510], nekoyoko[510]; ll usadiaga = 0, usadiagb = 0, nekodiaga = 0, nekodiagb = 0; int main() { ll n, u, v, m; cin >> n >> u >> v >> m; fill(usa, usa + 1000010, plglg(-1, -1)); fill(neko, neko + 1000010, plglg(-1, -1)); REP(i, 0, n) { REP(j, 0, n) { ll p; cin >> p; usa[p] = plglg(i, j); } } REP(i, 0, n) { REP(j, 0, n) { ll p; cin >> p; neko[p] = plglg(i, j); } } ll num[m]; REP(i, 0, m) { cin >> num[i]; } fill(usatate, usatate + 510, 0); fill(usayoko, usayoko + 510, 0); fill(nekotate, nekotate + 510, 0); fill(nekoyoko, nekoyoko + 510, 0); ll usanum = 0; ll nekonum = 0; REP(i, 0, m) { plglg usapos = usa[num[i]]; if (usapos.first != -1) { usatate[usapos.first]++; if (usatate[usapos.first] == n) { usanum++; } if (n >= 2) { usayoko[usapos.second]++; if (usayoko[usapos.second] == n) { usanum++; } if (usapos.first == usapos.second) { usadiaga++; if (usadiaga == n) { usanum++; } } if (usapos.first == n - 1 - usapos.second) { usadiagb++; if (usadiagb == n) { usanum++; } } } } plglg nekopos = neko[num[i]]; if (nekopos.first != -1) { nekotate[nekopos.first]++; if (nekotate[nekopos.first] == n) { nekonum++; } if (n >= 2) { nekoyoko[nekopos.second]++; if (nekoyoko[nekopos.second] == n) { nekonum++; } if (nekopos.first == nekopos.second) { nekodiaga++; if (nekodiaga == n) { nekonum++; } } if (nekopos.first == n - 1 - nekopos.second) { nekodiagb++; if (nekodiagb == n) { nekonum++; } } } } // REP(i, 0, n) { // cout << usatate[i] << " " << usayoko[i] << " " << nekotate[i] << " " << nekoyoko[i] << endl; // } // cout << num[i] << " " << usadiaga << " " << usadiagb << " " << nekodiaga << " " << nekodiagb << endl; // cout << "aaa" << endl; if (usanum >= u && nekonum < v) { cout << "USAGI" << endl; return 0; } else if (usanum < u && nekonum >= v) { cout << "NEKO" << endl; return 0; } else if (usanum >= u && nekonum >= v) { cout << "DRAW" << endl; return 0; } } cout << "DRAW" << endl; }
#include "bits/stdc++.h" using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, u, v, m; cin >> n >> u >> v >> m; vector<vector<int>> usagi(n + 1, vector<int>(n + 1, 0)); vector<vector<int>> neko(n + 1, vector<int>(n + 1, 0)); map<int, pair<int,int>> usagi_dayo, neko_dayo; /* input 1 */ for (int i = 1; i <= n;i++) for (int j = 1; j <= n;j++) { cin >> usagi[i][j]; usagi_dayo[usagi[i][j]] = { i,j }; } for (int i = 1; i <= n;i++) for (int j = 1; j <= n;j++) { cin >> neko[i][j]; neko_dayo[neko[i][j]] = { i,j }; } /* initialize */ /* yoko := sum of x axis tate := sum of y axis naname := lower_right_diagonal(0),upper_right_diagonal(1) */ vector<int> usagi_yoko(n+1, 0), usagi_tate(n+1, 0), usagi_naname(2, 0); vector<int> neko_yoko(n+1, 0), neko_tate(n+1, 0), neko_naname(2, 0); for (int i = 1; i <= n;i++) { for (int j = 1; j <= n;j++) { // usagi[tate][yoko] // tate[tate][yoko] if (i == j) { usagi_naname[0]++; neko_naname[0]++; } if (i + j == n + 1) { usagi_naname[1]++; neko_naname[1]++; } usagi_tate[i]++; usagi_yoko[j]++; neko_tate[i]++; neko_yoko[j]++; } } /* input 2 */ vector<int> card(m); for (int i = 0; i < m;i++) cin >> card[i]; /* solve */ for (int i = 0; i < m;i++) { auto usasa = usagi_dayo[card[i]]; auto nekoko = neko_dayo[card[i]]; /* usagi */ if (usasa.first != 0 && usasa.second != 0) { if (n == 1) { u--; } else { if (usasa.first == usasa.second) { usagi_naname[0]--; if (usagi_naname[0] <= 0)u--; } if (usasa.first + usasa.second == n + 1) { usagi_naname[1]--; if (usagi_naname[1] <= 0)u--; } usagi_tate[usasa.first]--; usagi_yoko[usasa.second]--; if (usagi_tate[usasa.first] <= 0)u--; if (usagi_yoko[usasa.second] <= 0)u--; } } /* neko */ if (nekoko.first != 0 && nekoko.second != 0) { if (n == 1) { v--; } else { if (nekoko.first == nekoko.second) { neko_naname[0]--; if (neko_naname[0] <= 0)v--; } if (nekoko.first + nekoko.second == n + 1) { neko_naname[1]--; if (neko_naname[1] <= 0)v--; } neko_tate[nekoko.first]--; neko_yoko[nekoko.second]--; if (neko_tate[nekoko.first] <= 0)v--; if (neko_yoko[nekoko.second] <= 0)v--; } } if (u <= 0 && v <= 0) { cout << "DRAW" << endl; return 0; } else if (u <= 0) { cout << "USAGI" << endl; return 0; } else if (v <= 0) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include<cstdio> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int n,m,card[100000]; int solve(const int A[500][500],int win){ // win : ツ堕オツつヲツづゥツづ猟つォツ療アツづ個古つ青? static int X[1000001],Y[1000001]; rep(i,1000001) X[i]=-1; rep(i,n) rep(j,n) X[A[i][j]]=j, Y[A[i][j]]=i; int tate[500]={},yoko[500]={},naname1=0,naname2=0; rep(i,m){ if(X[card[i]]==-1) continue; int x=X[card[i]],y=Y[card[i]]; if(++tate[x]==n) win--; if(++yoko[y]==n) win--; if(x-y== 0 && ++naname1==n) win--; if(x+y==n-1 && ++naname2==n) win--; if(n==1) win+=3; if(win<=0) return i; } return m; } int main(){ int usagi,neko; scanf("%d%d%d%d",&n,&usagi,&neko,&m); static int U[500][500],N[500][500]; rep(i,n) rep(j,n) scanf("%d",U[i]+j); rep(i,n) rep(j,n) scanf("%d",N[i]+j); rep(i,m) scanf("%d",card+i); int ans_u=solve(U,usagi); int ans_n=solve(N,neko); if (ans_u<ans_n) puts("USAGI"); else if(ans_u>ans_n) puts("NEKO"); else puts("DRAW"); return 0; }
#include <bits/stdc++.h> #define r(i,n) for(int i=0;i<n;i++) #define fi first #define se second #define mk make_pair using namespace std; int n,play[2],m,card[100001]; int h[501],w[501],na[2]; int p[2][501][501]; bool b[1000001]; int check(int x){ map<int,pair<int,int> >ma; memset(h,0,sizeof(h)); memset(w,0,sizeof(w)); memset(b,0,sizeof(b)); memset(na,0,sizeof(na)); r(i,n)r(j,n)ma[p[x][i][j]]=mk(i,j),b[p[x][i][j]]=1; r(i,m)if(b[card[i]]){ int f=ma[card[i]].fi,ans=0; int s=ma[card[i]].se; h[f]++;w[s]++; if(f==s)na[0]++; if(f+s==n-1)na[1]++; r(i,n)if(h[i]>=n)ans++; r(i,n)if(w[i]>=n)ans++; r(i,2)if(na[i]>=n)ans++; if(n==1&&ans/4>=play[x])return i; if(n!=1&&ans>=play[x])return i; } return 1e9; } int main(){ cin>>n>>play[0]>>play[1]>>m; r(k,2)r(i,n)r(j,n)cin>>p[k][i][j]; r(i,m)cin>>card[i]; int usagi=check(0); int neko=check(1); if(usagi==neko)cout<<"DRAW"<<endl; else if(usagi<neko)cout<<"USAGI"<<endl; else cout<<"NEKO"<<endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i,k,n) for(int i = (k); i < (n); i++) #define REP(i,n) FOR(i,0,n) #define ALL(a) a.begin(), a.end() #define MS(m,v) memset(m,v,sizeof(m)) #define D10 fixed<<setprecision(10) typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; typedef long double ld; const int MOD = 1000000007; const int INF = MOD + 1; const ld EPS = 1e-10; template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); } template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); } /*--------------------template--------------------*/ int main() { int n, u, v, m; cin >> n >> u >> v >> m; vector<vector<pii>> cat(1111111), rab(1111111); REP(i, n)REP(j, n) { int t; cin >> t; cat[t].push_back(pii(i, j)); } REP(i, n)REP(j, n) { int t; cin >> t; rab[t].push_back(pii(i, j)); } vi in(m); REP(i, m) cin >> in[i]; if (n == 1) { int c = INF, r = INF; REP(i, m) { if (cat[in[i]].size() >= 1 && c == INF) c = i; if (rab[in[i]].size() >= 1 && r == INF) r = i; } if (c < r&&u == 1) puts("USAGI"); else if (r < c&&v == 1) puts("NEKO"); else if (c == r&&u == 1 && v == 1) puts("DRAW"); else if (u >= 2 && v >= 2) puts("DRAW"); else if (c >= r&&u == 1 && c != INF) puts("USAGI"); else if (r >= c&&v == 1 && v != INF) puts("NEKO"); else puts("DRAW"); return 0; } vi catx(n), caty(n), cato(2), rabx(n), raby(n), rabo(2); int cntc = 0, cntr = 0; int ans = -1; REP(i, m) { int t = in[i]; REP(j, cat[t].size()) { int x = cat[t][j].first, y = cat[t][j].second; catx[x]++; caty[y]++; if (x == y) cato[0]++; if (x + y == n - 1) cato[1]++; if (catx[x] == n) cntc++; if (caty[y] == n) cntc++; if (cato[0] == n) { cato[0] = 0; cntc++; } if (cato[1] == n) { cato[1] = 0; cntc++; } } REP(j, rab[t].size()) { int x = rab[t][j].first, y = rab[t][j].second; rabx[x]++; raby[y]++; if (x == y) rabo[0]++; if (x + y == n - 1) rabo[1]++; if (rabx[x] == n) cntr++; if (raby[y] == n) cntr++; if (rabo[0] == n) { rabo[0] = 0; cntr++; } if (rabo[1] == n) { rabo[1] = 0; cntr++; } } if (cntc >= u&&cntr >= v) break; else if (cntc >= u) { ans = 0; break; } else if (cntr >= v) { ans = 1; break; } } if (ans == -1) puts("DRAW"); else if (ans == 0) puts("USAGI"); else puts("NEKO"); return 0; }
#include <cstdio> #include <algorithm> #include <vector> #include <unordered_set> #include <unordered_map> #include <bitset> using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) typedef long long ll; unordered_set<int> usetrow[500], usetcol[500], usetdia[2]; unordered_set<int> nsetrow[500], nsetcol[500], nsetdia[2]; unordered_set<int> uuse, nuse; unordered_map<int, int> ucard2rowindex; unordered_map<int, int> ucard2colindex; unordered_map<int, int> ncard2rowindex; unordered_map<int, int> ncard2colindex; int main() { int N, U, V, M; scanf("%d%d%d%d",&N,&U,&V,&M); rep(i, N) rep(j, N) { int x; scanf("%d", &x); uuse.insert(x); usetrow[i].insert(x); ucard2rowindex[x] |= i; ucard2colindex[x] |= j; usetcol[j].insert(x); if(i == j) usetdia[0].insert(x); if(i == N-1-j) usetdia[1].insert(x); } rep(i, N) rep(j, N) { int x; scanf("%d", &x); nuse.insert(x); nsetrow[i].insert(x); nsetcol[j].insert(x); ncard2rowindex[x] = i; ncard2colindex[x] = j; if(i == j) nsetdia[0].insert(x); if(i == N-1-j) nsetdia[1].insert(x); } if(N == 1) { rep(_, M) { int x; scanf("%d", &x); if(uuse.count(x) && nuse.count(x)) { if(U == 1 && U == V) { puts("DRAW"); } if(U == 1 && U < V) { puts("USAGI"); } else if(V == 1 && V < U) { puts("NEKO"); } else { puts("DRAW"); } return 0; } if(uuse.count(x) && U == 1) { puts("USAGI"); return 0; } if(nuse.count(x) && V == 1) { puts("NEKO"); return 0; } } puts("DRAW"); return 0; } int u = 0, v = 0; bool udiaskip = 0; bool vdiaskip = 0; rep(_, M) { int card; scanf("%d", &card); if(uuse.count(card)) { if(!udiaskip) { rep(i, 2) { if(usetdia[i].count(card)) { usetdia[i].erase(card); if(usetdia[i].empty()) { udiaskip = 1; u++; } } } } { auto iter = ucard2rowindex.find(card); if(iter != ucard2rowindex.end()) { auto idx = iter->second; usetrow[idx].erase(card); if(usetrow[idx].empty()) u++; ucard2rowindex.erase(card); } } { auto iter = ucard2colindex.find(card); if(iter != ucard2colindex.end()) { auto idx = iter->second; usetcol[idx].erase(card); if(usetcol[idx].empty()) u++; ucard2colindex.erase(card); } } } if(nuse.count(card)) { if(!vdiaskip) { rep(i, 2) { if(nsetdia[i].count(card)) { nsetdia[i].erase(card); if(nsetdia[i].empty()) { v++; vdiaskip = 1; } } } } { auto iter = ncard2rowindex.find(card); if(iter != ncard2rowindex.end()) { auto idx = iter->second; nsetrow[idx].erase(card); if(nsetrow[idx].empty()) v++; ncard2rowindex.erase(card); } } { auto iter = ncard2colindex.find(card); if(iter != ncard2colindex.end()) { auto idx = iter->second; nsetcol[idx].erase(card); if(nsetcol[idx].empty()) v++; ncard2colindex.erase(card); } } } if(U <= u && V > v) { puts("USAGI"); return 0; } if(U > u && V <= v) { puts("NEKO"); return 0; } if(U <= u && V <= v) break; } puts("DRAW"); return 0; }
#include <iostream> #include <algorithm> #include <iomanip> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; int add(vector<int> &v, int x, int y){ v[x]++; return v[x] >= y; } int main() { int n, a, b, m; cin >> n >> a >> b >> m; if(n == 1){ if(a >= 2) a = INF<int>; if(b >= 2) b = INF<int>; } using P = pair<int, int>; map<int, P> v, u; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int y; cin >> y; v[y] = {i, j}; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int y; cin >> y; u[y] = {i, j}; } } vector<int> x(2*n+2), y(2*n+2); int X = 0, Y = 0; for (int i = 0; i < m; ++i) { int z; scanf("%d", &z); if(v.count(z)){ auto p = v[z]; if(add(x, p.first, n)) X++; if(add(x, p.second+n, n)) X++; if(p.first == p.second) { if(add(x, 2*n, n)){ X++; } } if(p.first == n-p.second-1) { if(add(x, 2*n+1, n)){ X++; } } } if(u.count(z)){ auto p = u[z]; if(add(y, p.first, n)) Y++; if(add(y, p.second+n, n)) Y++; if(p.first == p.second) { if(add(y, 2*n, n)){ Y++; } } if(p.first == n-p.second-1) { if(add(y, 2*n+1, n)){ Y++; } } } int f = X >= a, g = Y >= b; if(f+g == 1){ puts(f ? "USAGI" : "NEKO"); return 0; }else if(f+g >= 2){ puts("DRAW"); return 0; } } puts("DRAW"); return 0; }
#include <iostream> #include <vector> #include <utility> using namespace std; int main(){ int n,m, g[2]; cin >> n >> g[0] >> g[1] >> m; vector<vector<pair<int,int> > > sheet(2, vector<pair<int,int> >((int)1e6+1, make_pair(-1,-1))); for(int k=0; k<2; k++){ for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ int num; cin >> num; sheet[k][num] = make_pair(i,j); } } } vector<vector<int> > bingo1(2, vector<int>(n+1, 0)), bingo2(2, vector<int>(n+1, 0)); int winner=-1; for(int i=0; i<m; i++){ int num; cin >> num; if(winner!=-1) continue; for(int j=0; j<2; j++){ if(sheet[j][num].first!=-1){ if(n==1){ g[j]--; continue; } int x=sheet[j][num].first; int y=sheet[j][num].second; bingo1[j][x]++; bingo2[j][y]++; if(bingo1[j][x]==n) g[j]--; if(bingo2[j][y]==n) g[j]--; if(x==y){ bingo1[j][n]++; if(bingo1[j][n]==n) g[j]--; } if(x+y==n-1){ bingo2[j][n]++; if(bingo2[j][n]==n) g[j]--; } } } if(g[0]<=0){ if(g[1]<=0){ winner=2; }else{ winner=0; } }else{ if(g[1]<=0){ winner=1; } } } if(winner==0){ cout << "USAGI" << endl; }else if(winner==1){ cout << "NEKO" << endl; }else{ cout << "DRAW" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define lps(i,j,n) for(int i=j;i<n;i++) #define lp(i,n) lps(i,0,n) #define DEKAI 1000000007 #define INF (1<<28) #define int long long pair<int,int> l[1000001],l2[1000001]; int nx[501],ny[501],ux[501],uy[501],nn1,nn2,uu1,uu2; signed main(){ int n,u,v,m; cin>>n>>u>>v>>m; lp(z,2){ lp(i,n){ lp(j,n){ int a; cin>>a; if(z==0){ l[a]=make_pair(i+1,j+1); } if(z==1){ l2[a]=make_pair(i+1,j+1); } } } } int us=0,nek=0,stat=0; lp(i,m){ int a; cin>>a; if(stat==1) continue; pair<int,int> usrg=l[a]; pair<int,int> nekrg=l2[a]; if(usrg.first!=0||usrg.second!=0){ ux[usrg.first]++; if(ux[usrg.first]==n) us++; uy[usrg.second]++; if(uy[usrg.second]==n) us++; if(usrg.first==usrg.second){ uu1++; if(uu1==n) us++; } if(usrg.first+usrg.second==n+1){ uu2++; if(uu2==n) us++; } } if(nekrg.first!=0||nekrg.second!=0){ nx[nekrg.first]++; if(nx[nekrg.first]==n) nek++; ny[nekrg.second]++; if(ny[nekrg.second]==n) nek++; if(nekrg.first==nekrg.second){ nn1++; if(nn1==n) nek++; } if(nekrg.first+nekrg.second==n+1){ nn2++; if(nn2==n) nek++; } } if(n==1){ if(nek!=0) nek=1; if(us!=0) us=1; } if(us>=u&&nek<v){ cout<<"USAGI"<<endl; stat=1;; } if(us>=u&& nek>=v){ cout<<"DRAW"<<endl; stat=1; } if(us<u&&nek>=v){ cout<<"NEKO"<<endl; stat=1; } //cout<<us<<" "<<nek<<endl; } if(stat==0){ cout<<"DRAW"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; int n, u, v, m; int a[510][510], b[510][510]; int c[100010]; int f[510][510], g[510][510]; pii posa[1000010], posb[1000010]; template <size_t N, size_t M> bool check(int cnt, int (&used)[N][M]) { int res = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!used[i][j]) break; if (j + 1 == n) res++; } } if (n > 1) { for (int j = 0; j < n; j++) { for (int i = 0; i < n; i++) { if (!used[i][j]) break; if (i + 1 == n) res++; } } for (int i = 0; i < n; i++) { if (!used[i][i]) break; if (i + 1 == n) res++; } for (int i = 0; i < n; i++) { if (!used[i][n - i - 1]) break; if (i + 1 == n) res++; } } return res >= cnt; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); fill_n((pii*)posa, 1000010, pii(-1, -1)); fill_n((pii*)posb, 1000010, pii(-1, -1)); cin >> n >> u >> v >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; posa[a[i][j]] = pii(i, j); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> b[i][j]; posb[b[i][j]] = pii(i, j); } } for (int i = 0; i < m; i++) { cin >> c[i]; } for (int i = 0; i < m; i++) { pii p = posa[c[i]], q = posb[c[i]]; if (p.first >= 0) f[p.first][p.second] = true; if (q.first >= 0) g[q.first][q.second] = true; bool oka = check(u, f); bool okb = check(v, g); if (oka || okb) { if (oka ^ okb) { cout << (oka ? "USAGI" : "NEKO") << endl; } else { cout << "DRAW" << endl; } return 0; } } cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> template <typename T> class BIT { int sz; std::vector<T> node; public: BIT(int sz): sz(sz+1), node(std::vector<T>(sz+1, 0)) {} void add(int idx, T val) { while(idx < sz) { node[idx] += val; idx += idx & -idx; } } int sum(int idx) { T res = 0; while(idx > 0) { res += node[idx]; idx -= idx & -idx; } return res; } }; using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vector<int>>; using vll = vector<ll>; using vvll = vector<vector<ll>>; const double eps = 1e-10; const int MOD = 1000000007; const int INF = 1000000000; const ll LINF = 1ll<<50; template<typename T> void printv(const vector<T>& s) { for(int i=0;i<(int)(s.size());++i) { cout << s[i]; if(i == (int)(s.size())-1) cout << endl; else cout << " "; } } int check(const vector<vector<int>> &mat, const P &p, vector<BIT<int>> &bit) { int res = 0; int n = (int)(mat.size()); int r = p.first, c = p.second; bit[r].add(c+1, 1); if(bit[r].sum(n) == n) res++; bit[n + c].add(r+1, 1); if(bit[n + c].sum(n) == n) res++; if(r == c) { bit[2*n].add(c+1, 1); if(bit[2*n].sum(n) == n) res++; } if(r == n - c - 1) { bit[2*n+1].add(c+1, 1); if(bit[2*n+1].sum(n) == n) res++; } return res; } int main() { cin.tie(0); cout << fixed << setprecision(10); int n, u, v, m; cin >> n >> u >> v >> m; vector<vector<int>> usa(n, vector<int>(n)), neko(n, vector<int>(n)); map<int, P> usamp, nekomp; map<int, bool> usasel, nekosel; for(int i=0;i<n;++i) { for(int j=0;j<n;++j) { cin >> usa[i][j]; usamp[usa[i][j]] = {i, j}; usasel[usa[i][j]] = true; } } for(int i=0;i<n;++i) { for(int j=0;j<n;++j) { cin >> neko[i][j]; nekomp[neko[i][j]] = {i, j}; nekosel[neko[i][j]] = true; } } vector<int> tra(m); for(int i=0;i<m;++i) { cin >> tra[i]; } vector<BIT<int>> usabit(2*n+2, BIT<int>(n+1)), nekobit(2*n+2, BIT<int>(n+1)); int usacnt = 0, nekocnt = 0; bool usawin = false, nekowin = false; for(int i=0;i<m;++i) { if(usasel[tra[i]]) { if(n == 1) { usacnt++; } else { P usap = usamp[tra[i]]; usacnt += check(usa, usap, usabit); } if(usacnt >= u) usawin = true; } if(nekosel[tra[i]]) { if(n == 1) { nekocnt++; } else { P nekop = nekomp[tra[i]]; nekocnt += check(neko, nekop, nekobit); } if(nekocnt >= v) nekowin = true; } if(usawin || nekowin) break; } if(usawin && nekowin) { cout << "DRAW" << endl; } else if(usawin) { cout << "USAGI" << endl; } else if(nekowin) { cout << "NEKO" << endl; } else { cout << "DRAW" << endl; } }
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <fstream> //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; const ll INF = 1LL << 40; const ll LIM = 100 * 1000; struct st { st(ll n) : v(vector<vector<ll>>(n, vector<ll>(n))), row(n,0), column(n,0), cross(2,0) { } void in(ll n) { for(ll y = 0; y < n; y ++) for(ll x = 0; x < n; x++) { cin >> v[x][y]; m[v[x][y]] = pll(x, y); } } bool find(ll x) { if(m.find(x) == m.end()) { return false; } return true; } void draw(ll w) { if(!find(w)) { return; } ll n = v.size(); pll p = m[w]; column[p.first] ++; row[p.second] ++; if (p.first == p.second) { cross[0] ++; } if (p.first == n - p.second - 1) { cross[1] ++; } } ll cnt(ll n) { ll ret = 0; for(auto c:column) if(c == n) ret ++; if (n == 1) { return ret; } for(auto r:row) if(r == n) ret ++; for(auto c:cross) if(c == n) ret ++; return ret; } vector<ll> row; vector<ll> column; vector<ll> cross; vector<vector<ll>> v; map<ll, pll> m; }; int solve(void); int main(void) { while (solve()) { } return 0; } int solve(void) { ll n, u, v, m; cin >> n >> u >> v >> m; st us(n), nk(n); us.in(n); nk.in(n); st s[] = {us, nk}; ll w[] = {u, v}; const char* ch[] = {"USAGI", "NEKO"}; for (ll i = 0; i < m; i++) { ll d; cin >> d; for(ll j = 0; j < 2; j++) { s[j].draw(d); } for(ll j = 0; j < 2; j++) if (s[j].cnt(n) >= w[j]) { if (s[0].cnt(n) >= w[0] && s[1].cnt(n) >= w[1]) { cout << "DRAW" << endl; return 0; } cout << ch[j] << endl; return 0; } if (i == m - 1) { cout << "DRAW" << endl; return 0; } } return 0; }
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 500; const int MAX_C = 1000000; const string ans[] = { "USAGI", "NEKO", "DRAW" }; /* typedef */ typedef vector<int> vi; typedef map<int,int> mi; struct Bingo { int n, nn; int d0, d1; vi hs, vs; mi cs; Bingo(int _n): n(_n), nn(_n * _n), d0(_n), d1(_n), hs(_n, _n), vs(_n, _n) {} void set(int d, int x, int y) { cs[d] = y * n + x; } int draw(int c) { mi::iterator mit = cs.find(c); if (mit == cs.end()) return 0; int x = mit->second % n, y = mit->second / n; cs.erase(mit); if (n == 1) return 1; int count = 0; if (! --hs[y]) count++; if (! --vs[x]) count++; if (x == y && ! --d0) count++; if (x + y == n - 1 && ! --d1) count++; return count; } }; /* global variables */ /* subroutines */ /* main */ int main() { int n, u, v, m; cin >> n >> u >> v >> m; Bingo bu(n), bv(n); for (int y = 0; y < n; y++) for (int x = 0; x < n; x++) { int d; cin >> d; bu.set(d, x, y); } for (int y = 0; y < n; y++) for (int x = 0; x < n; x++) { int d; cin >> d; bv.set(d, x, y); } int ul = 0, vl = 0; int st = 2; while (m--) { int c; cin >> c; ul += bu.draw(c); vl += bv.draw(c); //printf("ul=%d, vl=%d\n", ul, vl); int fin = 0; if (ul >= u) fin += 1; if (vl >= v) fin += 2; if (fin) { st = fin - 1; break; } } cout << ans[st] << endl; return 0; }
#include <array> #include <cstdlib> #include <iostream> #include <unordered_map> #include <vector> using namespace std; template<typename T> inline void chmin(T& a, const T& b) { if(a > b) a = b; } inline int update(const unordered_multimap<int, int>& idx, vector<int>& cnt, int card, int size) { int res = 0; auto range = idx.equal_range(card); while(range.first != range.second) { if(++cnt[range.first->second] == size) ++res; ++range.first; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); constexpr int RABBIT = 0; constexpr int CAT = 1; int n, m; array<int, 2> win; cin >> n >> win[RABBIT] >> win[CAT] >> m; unordered_multimap<int, int> row[2], col[2], dia[2]; vector<vector<int>> row_cnt(2, vector<int>(n, 0)), col_cnt(2, vector<int>(n, 0)), dia_cnt(2, vector<int>(2, 0)); for(int k = 0; k < 2; ++k) { for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { int number; cin >> number; row[k].insert(make_pair(number, i)); col[k].insert(make_pair(number, j)); if(i == j) dia[k].insert(make_pair(number, 0)); if(i + j == n - 1) dia[k].insert(make_pair(number, 1)); } } } int result = 0; array<int, 2> num; num.fill(0); while(m--) { int card; cin >> card; for(int k = 0; k < 2; ++k) { num[k] += update(row[k], row_cnt[k], card, n); num[k] += update(col[k], col_cnt[k], card, n); num[k] += update(dia[k], dia_cnt[k], card, n); if(n == 1) chmin(num[k], 1); if(num[k] >= win[k]) result |= (1 << k); } if(result) break; } switch(result) { case (1 << RABBIT): cout << "USAGI" << endl; break; case (1 << CAT): cout << "NEKO" << endl; break; default: cout << "DRAW" << endl; break; } return EXIT_SUCCESS; }
#include <iostream> #include <algorithm> #include <map> using namespace std; typedef pair<int, int> P; const int N = 500; const int M = 1000000; int n, u, v, m; P data[2][M]; int tate[2][N], yoko[2][N], naname[2][2], cnt[2]; string solve(){ for(int k=0;k<2;k++){ cnt[k] = 0; naname[k][0] = naname[k][1] = n; for(int i=0;i<n;i++){ tate[k][i] = yoko[k][i] = n; } } bool fin = false; string res = "DRAW"; for(int i=0;i<m;i++){ int in; cin >> in; if(fin) continue; for(int k=0;k<2;k++){ int x = data[k][in-1].second, y = data[k][in-1].first; if(x == -1 && y == -1) continue; tate[k][x]--; if(tate[k][x] == 0) cnt[k]++; yoko[k][y]--; if(n > 1 && yoko[k][y] == 0) cnt[k]++; if(x == y){ naname[k][0]--; if(n > 1 && naname[k][0] == 0) cnt[k]++; } if(x + y == n-1){ naname[k][1]--; if(n > 1 && naname[k][1] == 0) cnt[k]++; } } if(cnt[0] >= u && cnt[1] < v){ fin = true; res = "USAGI"; } if(cnt[0] < u && cnt[1] >= v){ fin = true; res = "NEKO"; } } return res; } int main(){ while(cin >> n >> u >> v >> m){ fill(data[0], data[2], P(-1, -1)); for(int k=0;k<2;k++){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int in; cin >> in; data[k][in-1] = P(i, j); } } } cout << solve() << endl; } return 0; }
#include <iostream> #include <cstdio> #include <cmath> #include <cstdio> #include <cstring> #include <string> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <algorithm> #define REP(i,n,N) for(int i=(n);i<(int)N;i++) #define p(s) cout<<(s)<<endl #define ck(n,a,b) ((a)<=(n)&&(n)<(b)) #define F first #define S second typedef long long ll; using namespace std; const int inf=1e9; int card[100010]; int usa_row[510], usa_col[510], usa_d, usa_u, usa_line; int neko_row[510], neko_col[510], neko_d, neko_u, neko_line; int main() { int n, u, v, m; map<int, pair<int, int> > usa_map, neko_map; set<int> usa_s, neko_s; cin>>n>>u>>v>>m; REP(i, 0, n){ REP(j, 0, n){ int usa; cin>>usa; usa_s.insert(usa); usa_map[usa]=(make_pair(i, j)); } } REP(i, 0, n){ REP(j, 0, n){ int neko; cin>>neko; neko_s.insert(neko); neko_map[neko]=(make_pair(i, j)); } } REP(i, 0, m){ cin>>card[i]; } if(n==1){ REP(i,0,m){ if((usa_s.find(card[i]) != usa_s.end() && u <= 1) && (neko_s.find(card[i]) != neko_s.end() && v <= 1)){ cout<<"DRAW"<<endl; return 0; }else if(usa_s.find(card[i]) != usa_s.end() && u <= 1){ cout<<"USAGI"<<endl; return 0; }else if(neko_s.find(card[i]) != neko_s.end() && v <= 1){ cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; return 0; } REP(k, 0, m){ int num=card[k]; // usa if(usa_s.find(num)!=usa_s.end()) { int i=usa_map[num].first; int j=usa_map[num].second; usa_row[i]++; usa_col[j]++; if(i==j) usa_d++; if(i+j==n-1) usa_u++; if(usa_row[i]==n) usa_line++; if(usa_col[j]==n) usa_line++; if(usa_d==n) { usa_line++; usa_d=0; } if(usa_u==n) { usa_line++; usa_u=0; } } //neko if(neko_s.find(num)!=neko_s.end()){ int i=neko_map[num].first; int j=neko_map[num].second; neko_row[i]++; neko_col[j]++; if(i==j) neko_d++; if(i+j==n-1) neko_u++; if(neko_row[i]==n) neko_line++; if(neko_col[j]==n) neko_line++; if(neko_d==n) { neko_line++; neko_d=0; } if(neko_u==n){ neko_line++; neko_u=0; } } if(usa_line>=u && neko_line>=v){ cout<<"DRAW"<<endl; return 0; } else if(usa_line>=u){ cout<<"USAGI"<<endl; return 0; } else if(neko_line>=v){ cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define llong long long #define REP(i,n) for(auto i=0;i<n;++i) #define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr) #define FOR(i,a,b) for(auto i=a;i<b++i) #define ALL(v) v.begin(),v.end() #define pb push_back using namespace std; int win(vector<vector<int> > &v, vector<int> &c, int u){ int n = v.size(), m = c.size(); vector<vector<bool> > ismark(n, vector<bool>(n,false)); map<int, pair<int, int> > idxs; for(int i = 0; i < n; i++)for(int j = 0; j < n; j++){ idxs[v[i][j]] = make_pair(i,j); } vector<bool> bingo(2*n+2,false); for(int i = 0; i < m; i++){ auto element = idxs.find(c[i]); if(element == idxs.end())continue; auto idx = element->second; ismark[idx.first][idx.second] = true; bool row = true, col = true; for(int j = 0; j < n; j++) if(!ismark[j][idx.second]){ row=false; break; } for(int j = 0; j < n; j++) if(!ismark[idx.first][j]){ col=false; break; } bingo[idx.first] = row || bingo[idx.first]; if(n != 1){ bingo[n+idx.second] = col || bingo[n+idx.second]; } { bool s = true, bs = true; for(int j = 0; j < n; j++) if(!ismark[j][j]){ s = false; break; } for(int j = 0; j < n; j++) if(!ismark[j][n-j-1]){ bs = false; break; } if(n != 1){ bingo[2*n] = s || bingo[2*n]; bingo[2*n+1] = bs || bingo[2*n+1]; } } int b = 0; for(auto e : bingo){ if(e)b++; } if(b >= u)return i; } return m; } int main(){ int n,u,v,m;cin >> n >> u >> v >> m; vector<vector<int> > usa(n,vector<int>(n)),nek(n,vector<int>(n)); for(auto &v :usa)for(auto &e : v)cin >> e; for(auto &v :nek)for(auto &e : v)cin >> e; vector<int> c(m); for(auto &e : c)cin >> e; int usagi = win(usa, c, u); int neko = win(nek, c, v); if(usagi < neko)cout << "USAGI" << endl; else if(usagi > neko)cout << "NEKO" << endl; else cout << "DRAW" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int N, U[2], M, A[2][500][500]; int sum[2][2][500], f[2], g[2]; vector< tuple< int, int, int > > memo[1000001]; int main() { scanf("%d %d %d %d", &N, &U[0], &U[1], &M); for(int k = 0; k < 2; k++) { for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { scanf("%d", &A[k][i][j]); memo[A[k][i][j]].emplace_back(k, i, j); } sum[k][0][i] = sum[k][1][i] = N; } f[k] = g[k] = N; } while(M--) { int num; scanf("%d", &num); for(auto& d : memo[num]) { int k, i, j; tie(k, i, j) = d; U[k] -= --sum[k][0][i] == 0; if(N > 1) { U[k] -= --sum[k][1][j] == 0; if(i == j) U[k] -= --f[k] == 0; if(j == N - i - 1) U[k] -= --g[k] == 0; } } if(U[0] <= 0 || U[1] <= 0) { if(U[0] <= 0 && U[1] <= 0) break; puts(U[1] <= 0 ? "NEKO" : "USAGI"); exit(0); } } puts("DRAW"); }
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<set> #include<utility> #include<cmath> #include<cstring> #include<queue> #include<stack> #include<cstdio> #include<sstream> #include<iomanip> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define pb push_back #define mp make_pair #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) using namespace std; //kaewasuretyuui typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<vp> vvp; typedef pair<int,pii> pip; typedef vector<pip>vip; const double PI=acos(-1); const double EPS=1e-8; const int inf=1e9; int main(){ int n,nu,nn,l; cin>>n>>nu>>nn>>l; map<int,pii>mu,mn; rep(i,n)rep(j,n){ int a; cin>>a; mu[a]=pii(i+1,j+1); } rep(i,n)rep(j,n){ int a; cin>>a; mn[a]=pii(i+1,j+1); } vi cou(2*n+2),con(2*n+2); vi num(l); rep(i,l)cin>>num[i]; rep(i,l){ pii p=mu[num[i]]; if(p.first||p.second){ if(n==1){ nu--; }else{ int x=p.first-1,y=p.second-1; cou[x]++;cou[n+y]++; if(x==y){ cou[2*n]++; if(cou[2*n]==n)nu--; } if(x+y==n-1){ cou[2*n+1]++; if(cou[2*n+1]==n)nu--; } if(cou[x]==n)nu--; if(cou[n+y]==n)nu--; } } p=mn[num[i]]; if(p.first||p.second){ if(n==1){ nn--; }else{ int x=p.first-1,y=p.second-1; con[x]++;con[n+y]++; if(x==y){ con[2*n]++; if(con[2*n]==n)nn--; } if(x+y==n-1){ con[2*n+1]++; if(con[2*n+1]==n)nn--; } if(con[x]==n)nn--; if(con[n+y]==n)nn--; } } if(nu<=0||nn<=0){ if(nu<=0&&nn<=0)cout<<"DRAW"<<endl; else if(nu<=0)cout<<"USAGI"<<endl; else cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; }
#include <bits/stdc++.h> using namespace std; #define for_(i,a,b) for(int i=(a);i<(b);++i) struct Pos { int x, y; }; int n, u, v, m, usaneko[2][1002]; unordered_map< int, Pos > usaneko_map[2]; int main() { cin >> n >> u >> v >> m; for_(un,0,2) { for_(i,0,n) for_(j,0,n) { int c; cin >> c; usaneko_map[un][c] = Pos{j, i}; } } for_(un,0,2) for_(i,0,n+n+2) usaneko[un][i] = n; int cnt[2] = {0}; for_(i,0,m) { int c; cin >> c; for_(un,0,2) { if (usaneko_map[un].count(c)) { Pos p = usaneko_map[un][c]; if (--usaneko[un][p.y] == 0) ++cnt[un]; if (n > 1 && --usaneko[un][n + p.x] == 0) ++cnt[un]; if (n > 1 && p.x == p.y && --usaneko[un][n + n] == 0) ++cnt[un]; if (n > 1 && p.x == n - p.y - 1 && --usaneko[un][n + n + 1] == 0) ++cnt[un]; } } if (cnt[0] >= u && cnt[1] < v) { cout << "USAGI" << endl; return 0; } if (cnt[0] < u && cnt[1] >= v) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; }
#include <bits/stdc++.h> #define N 1000001 #define f first #define s second using namespace std; typedef pair <int,int> P; int n,u,v,m,num[N]; P U[N],V[N]; void in(P a[]){ for(int i=1;i<=n;i++) for(int j=1,b;j<=n;j++) cin>>b,a[b]=P(i,j); } int game(P A[],int B){ int ta[501]={},yo[501]={},X[2]={},cnt=0; if(n==1)cnt-=3; for(int i=0;i<m;i++){ int y=A[num[i]].f,x=A[num[i]].s; if(x==0)continue; X[0]+=(x==y); X[1]+=(x+y==n+1); if(X[0]==n) X[0]=-1e9,cnt++; if(X[1]==n) X[1]=-1e9,cnt++; cnt+=(++ta[y]==n)+(++yo[x]==n); if(cnt>=B)return i; } return m; } int main(){ cin>>n>>u>>v>>m; in(U),in(V); for(int i=0;i<m;i++) cin>>num[i]; int Uscore=game(U,u); int Vscore=game(V,v); if(Uscore<Vscore) cout <<"USAGI"<<endl; else if(Uscore>Vscore)cout <<"NEKO"<<endl; else cout<<"DRAW"<<endl; return 0; }
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; int n, u, v, m; bool a[500][500], b[500][500]; int xa[1000000], ya[1000000], xb[1000000], yb[1000000]; int p(bool a[][500], int x, int y) { a[x][y] = 1; if (n == 1)return 1; int res = 0; bool ok = 1; rep(i, n)ok &= a[x][i]; if (ok)res++; ok = 1; rep(i, n)ok &= a[i][y]; if (ok)res++; if (x == y) { ok = 1; for (int i = 0, j = 0; i < n; i++, j++)ok &= a[i][j]; if (ok)res++; } if (x + y == n - 1) { ok = 1; for (int i = 0, j = n - 1; i < n; i++, j--)ok &= a[i][j]; if (ok)res++; } return res; } int main() { scanf("%d%d%d%d", &n, &u, &v, &m); memset(xa, -1, sizeof(xa)); memset(xb, -1, sizeof(xb)); rep(i, n)rep(j, n) { int c; scanf("%d", &c); c--; xa[c] = i; ya[c] = j; } rep(i, n)rep(j, n) { int c; scanf("%d", &c); c--; xb[c] = i; yb[c] = j; } int c1 = 0, c2 = 0; rep(i, m) { int c; scanf("%d", &c); c--; if (~xa[c])c1 += p(a, xa[c], ya[c]); if (~xb[c])c2 += p(b, xb[c], yb[c]); if (c1 >= u) { if (c2 >= v)puts("DRAW"); else puts("USAGI"); return 0; } else if (c2 >= v) { puts("NEKO"); return 0; } } puts("DRAW"); }