text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int main(){ int n, u, v, m; cin >> n >> u >> v >> m; vector<int> r = {u, v}; vector<vector<vector<int>>> A(2, vector<vector<int>>(n, vector<int>(n))); 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]; } } } vector<int> C(m); for (int i = 0; i < m; i++){ cin >> C[i]; } vector<int> ans(2); for (int i = 0; i < 2; i++){ int tv = m + 1; int fv = 0; while (tv - fv > 1){ int mid = (tv + fv) / 2; set<int> st; for (int j = 0; j < mid; j++){ st.insert(C[j]); } vector<vector<bool>> M(n, vector<bool>(n, false)); for (int j = 0; j < n; j++){ for (int k = 0; k < n; k++){ if (st.count(A[i][j][k])){ M[j][k] = true; } } } int cnt = 0; for (int j = 0; j < n; j++){ bool ok = true; for (int k = 0; k < n; k++){ if (!M[j][k]){ ok = false; } } if (ok){ cnt++; } } if (n > 1){ for (int k = 0; k < n; k++){ bool ok = true; for (int j = 0; j < n; j++){ if (!M[j][k]){ ok = false; } } if (ok){ cnt++; } } bool ok1 = true; for (int j = 0; j < n; j++){ if (!M[j][j]){ ok1 = false; } } if (ok1){ cnt++; } bool ok2 = true; for (int j = 0; j < n; j++){ if (!M[j][n - 1 - j]){ ok2 = false; } } if (ok2){ cnt++; } } if (cnt >= r[i]){ tv = mid; } else { fv = mid; } } ans[i] = tv; } if (ans[0] < ans[1]){ cout << "USAGI" << endl; } else if (ans[0] > ans[1]){ cout << "NEKO" << endl; } else { cout << "DRAW" << endl; } }
#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]; unordered_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); } 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 <algorithm> #include <unordered_map> #undef max #undef min constexpr int INF = 99999999; std::unordered_map<int, int> drawTable; // key:カードの数字 value:引く順番 int markNumber(std::vector<std::vector<int>>& mat, int minBingo) { std::vector<std::vector<int>> openTable; std::vector<int> eachMinBingoTurn; int bingoCount = 0; for (auto& line : mat) { openTable.push_back(std::vector<int>()); for (auto& x : line) { auto order = drawTable.find(x); if (order != drawTable.end()) { openTable.back().push_back(order->second); } else openTable.back().push_back(INF); } } // 横方向のビンゴ for (int i = 0; i < openTable.size(); i++) { int minTurn = 0; for (int j = 0; j < openTable[i].size(); j++) { minTurn = std::max(minTurn, openTable[i][j]); } eachMinBingoTurn.push_back(minTurn); } if (mat.size() > 1) { // 縦方向のビンゴ for (int i = 0; i < openTable.size(); i++) { int minTurn = 0; for (int j = 0; j < openTable[i].size(); j++) { minTurn = std::max(minTurn, openTable[j][i]); } eachMinBingoTurn.push_back(minTurn); } // ななめ方向のビンゴ int minTurn = 0; for (int i = 0; i < openTable.size(); i++) { minTurn = std::max(minTurn, openTable[i][i]); } eachMinBingoTurn.push_back(minTurn); // ななめ方向のビンゴ minTurn = 0; for (int i = 0; i < openTable.size(); i++) { minTurn = std::max(minTurn, openTable[i][openTable.size() - i - 1]); } eachMinBingoTurn.push_back(minTurn); } std::sort(eachMinBingoTurn.begin(), eachMinBingoTurn.end()); if (minBingo > eachMinBingoTurn.size()) return INF; return eachMinBingoTurn[minBingo-1]; } int main() { int n, u, v, m; std::vector<std::vector<int>> usaMat, nekoMat; std::vector<int> drawCards; std::cin >> n >> u >> v >> m; for (int i = 0; i < n; i++) { usaMat.push_back(std::vector<int>()); for (int j = 0; j < n; j++) { int a; std::cin >> a; usaMat.back().push_back(a); } } for (int i = 0; i < n; i++) { nekoMat.push_back(std::vector<int>()); for (int j = 0; j < n; j++) { int a; std::cin >> a; nekoMat.back().push_back(a); } } drawTable.reserve(100000); for (int i = 0; i < m; i++) { int a; std::cin >> a; drawTable.insert(std::make_pair(a, i)); } int nunUsaTurn = markNumber(usaMat, u); int nunNekoTurn = markNumber(nekoMat, v); if (nunUsaTurn < nunNekoTurn) { std::cout << "USAGI" << std::endl; return 0; } else if (nunNekoTurn < nunUsaTurn) { std::cout << "NEKO" << std::endl; return 0; } else if (nunNekoTurn == nunUsaTurn) { std::cout << "DRAW" << std::endl; return 0; } return 0; }
#include "bits/stdc++.h" using namespace std; using i64 = long long; const i64 MOD = i64(1e9) + 7; const i64 INF = i64(1e18) + 7; signed main(){ int n, u, v, m; cin >> n >> u >> v >> m; vector<vector<int>> usagi(n, vector<int>(n, 0)); vector<vector<int>> neko(n, vector<int>(n, 0)); map<int,pair<int,int>> usagi_set, neko_set; for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j){ cin >> usagi[i][j]; usagi_set[usagi[i][j]] = make_pair(i, j); } for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j){ cin >> neko[i][j]; neko_set[neko[i][j]] = make_pair(i, j); } vector<int> a(m); for(int i = 0; i < m; ++i) cin >> a[i]; unordered_map<int,int> usagi_h, usagi_w, usagi_hw, usagi_wh; unordered_map<int,int> neko_h, neko_w, neko_hw, neko_wh; int usagi_cnt = 0, neko_cnt = 0; for(auto& b : a){ if(usagi_set.find(b) != usagi_set.end()){ int x, y; tie(x, y) = usagi_set[b]; ++usagi_h[x]; ++usagi_w[y]; ++usagi_hw[x + y]; ++usagi_wh[x - y]; usagi_cnt += (usagi_h[x] == n); usagi_cnt += (usagi_w[y] == n); usagi_cnt += (usagi_hw[x + y] == n); usagi_cnt += (usagi_wh[x - y] == n); if(n == 1){ usagi_cnt = 1; } } if(neko_set.find(b) != neko_set.end()){ int x, y; tie(x, y) = neko_set[b]; ++neko_h[x]; ++neko_w[y]; ++neko_hw[x + y]; ++neko_wh[x - y]; neko_cnt += (neko_h[x] == n); neko_cnt += (neko_w[y] == n); neko_cnt += (neko_hw[x + y] == n); neko_cnt += (neko_wh[x - y] == n); if(n == 1){ neko_cnt = 1; } } if(usagi_cnt >= u && neko_cnt >= v){ cout << "DRAW" << endl; return 0; } if(usagi_cnt >= u && neko_cnt < v){ cout << "USAGI" << endl; return 0; } if(usagi_cnt < u && neko_cnt >= v){ cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include<deque> #include<queue> #include<vector> #include<algorithm> #include<iostream> #include<set> #include<cmath> #include<tuple> #include<string> #include<chrono> #include<functional> #include<iterator> #include<random> #include<unordered_set> #include<array> #include<map> #include<iomanip> #include<assert.h> #include<list> #include<bitset> #include<stack> #include<memory> using namespace std; using namespace std::chrono; typedef long long int llint; typedef double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ const llint mod=1000000007; const llint big=2.19e18+1; const long double pai=3.141592653589793238462643383279502884197; const long double eps=1e-15; template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;} template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;} llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);} llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;} template<class T> void SO(T& ve){sort(ve.begin(),ve.end());} template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());} template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();} template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();} int main(void){ int n,u,v,m,i,j;cin>>n>>u>>v>>m; vector<int>ut(n); vector<int>vt(n); vector<int>uy(n); vector<int>vy(n); if(n==1&&u>1){u=9999;} if(n==1&&v>1){v=9999;} int uq=0,vq=0,uw=0,vw=0; static pair<int,int> aaa[1000000]; static pair<int,int> bbb[1000000]; for(i=0;i<1000000;i++){aaa[i]=mp(-1,-1);bbb[i]=mp(-1,-1);} for(i=0;i<n;i++){ for(j=0;j<n;j++){ int x;cin>>x;x--; aaa[x]=mp(i,j); } } for(i=0;i<n;i++){ for(j=0;j<n;j++){ int x;cin>>x;x--; bbb[x]=mp(i,j); } } while(m--){ int x;cin>>x;x--; if(aaa[x]!=mp(-1,-1)){ ut[aaa[x].fir]++;if(ut[aaa[x].fir]==n){u--;} uy[aaa[x].sec]++;if(uy[aaa[x].sec]==n){u--;} if(aaa[x].fir==aaa[x].sec){uq++;if(uq==n){u--;}} if(aaa[x].fir+aaa[x].sec==n-1){uw++;if(uw==n){u--;}} } if(bbb[x]!=mp(-1,-1)){ vt[bbb[x].fir]++;if(vt[bbb[x].fir]==n){v--;} vy[bbb[x].sec]++;if(vy[bbb[x].sec]==n){v--;} if(bbb[x].fir==bbb[x].sec){vq++;if(vq==n){v--;}} if(bbb[x].fir+bbb[x].sec==n-1){vw++;if(vw==n){v--;}} } if(u<=0&&v<=0){cout<<"DRAW"<<endl;return 0;} if(u<=0){cout<<"USAGI"<<endl;return 0;} if(v<=0){cout<<"NEKO"<<endl;return 0;} } cout<<"DRAW"<<endl; return 0; }
#include<iostream> #include<cstring> using namespace std; int h, u, n, c, a, winner, p, usa, neko, usanana, usanana2, nekonana, nekonana2, usax[1145140], usay[1145140], nekox[1145140], nekoy[1145140], usabx[1000], usaby[1000], nekobx[1000], nekoby[1000]; int main() { memset(usax, 114514, sizeof(usax)); memset(usay, 114514, sizeof(usay)); memset(nekox, 114514, sizeof(nekox)); memset(nekoy, 114514, sizeof(nekoy)); cin >> h >> u >> n >> c; for (int i = 0; i < h; i++) { for (int j = 0; j < h; j++) { cin >> usa; usax[usa] = j; usay[usa] = i; } } for (int i = 0; i < h; i++) { for (int j = 0; j < h; j++) { cin >> neko; nekox[neko] = j; nekoy[neko] = i; } } winner = 3; usa = 0; neko = 0; for (int i = 0; i < c; i++) { cin >> a; if (h == 1) { if (usax[a] < 114514) { usa++; } if (nekox[a] < 114514) { neko++; } } else { p = 0; if (usax[a] < 114514) { usabx[usax[a]]++; if (usabx[usax[a]] == h) { usa += 1; } } if (usay[a] < 114514) { usaby[usay[a]]++; if (usaby[usay[a]] == h) { usa += 1; } } if (usax[a] < 114514) { if (usax[a] == usay[a]) { usanana++; } if (usax[a] == h - 1 - usay[a]) { usanana2++; } if (usanana == h) { usa += 1; usanana++; } if (usanana2 == h) { usa += 1; usanana2++; } } if (nekox[a] < 114514) { nekobx[nekox[a]]++; if (nekobx[nekox[a]] == h) { neko += 1; } } if (nekoy[a] < 114514) { nekoby[nekoy[a]]++; if (nekoby[nekoy[a]] == h) { neko += 1; } } if (nekox[a] < 114514) { if (nekox[a] == nekoy[a]) { nekonana++; } if (nekox[a] == h - 1 - nekoy[a]) { nekonana2++; } if (nekonana == h) { neko += 1; nekonana++; } if (nekonana2 == h) { neko += 1; nekonana2++; } } } if (winner == 3) { if (usa >= u && neko >= n) { winner = 2; } else if (usa >= u) { winner = 0; } else if (neko >= n) { 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 fi first #define se second #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define each(itr,v) for(auto itr:v) #define pb(s) push_back(s) #define mp(a,b) make_pair(a,b) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<<x<<endl #define maxch(x,y) x=max(x,y) #define minch(x,y) x=min(x,y) #define uni(x) x.erase(unique(all(x)),x.end()) #define exist(x,y) (find(all(x),y)!=x.end()) #define bcnt(x) bitset<32>(x).count() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<P, int> PPI; typedef pair<ll, ll> PL; typedef pair<P, ll> PPL; #define INF INT_MAX/3 #define MAX_N 1000 int n,u,v,m; int uc[555],ur[555],nc[555],nr[555],ucros[2],ncros[2]; map<int,P> usa,neko; int card[100010]; int main(){ scanf("%d%d%d%d",&n,&u,&v,&m); rep(i,n)rep(j,n){ int a; scanf("%d",&a); usa[a]=P(i,j); } rep(i,n)rep(j,n){ int a; scanf("%d",&a); neko[a]=P(i,j); } rep(i,m)scanf("%d",card+i); int ucnt=0,ncnt=0; rep(i,m){ int a=card[i]; if(usa.count(a)){ uc[usa[a].fi]++; if(uc[usa[a].fi]==n)ucnt++; ur[usa[a].se]++; if(ur[usa[a].se]==n)ucnt++; if(usa[a].fi==usa[a].se){ ucros[0]++; if(ucros[0]==n)ucnt++; } if(usa[a].fi+usa[a].se==n-1){ ucros[1]++; if(ucros[1]==n)ucnt++; } } if(neko.count(a)){ nc[neko[a].fi]++; if(nc[neko[a].fi]==n)ncnt++; nr[neko[a].se]++; if(nr[neko[a].se]==n)ncnt++; if(neko[a].fi==neko[a].se){ ncros[0]++; if(ncros[0]==n)ncnt++; } if(neko[a].fi+neko[a].se==n-1){ ncros[1]++; if(ncros[1]==n)ncnt++; } } //dbg(ucnt); dbg(ncnt); if(n==1){ minch(ucnt,1); minch(ncnt,1); } if(ucnt>=u&&ncnt>=v){ printf("DRAW\n"); return 0; }else if(ucnt>=u){ printf("USAGI\n"); return 0; }else if(ncnt>=v){ printf("NEKO\n"); return 0; } } printf("DRAW\n"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; const ll MOD = 1000000007; const int IINF = INT_MAX; const ll LLINF = LLONG_MAX; const int MAX_N = int(2e5 + 5); const double EPS = 1e-8; const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0}; #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define SORT(v) sort((v).begin(), (v).end()) #define ALL(v) (v).begin(), (v).end() struct board{ int n, w, ok=0, nnm[2]{}; map<int,P> pos; vector<int> rcnt, ccnt; void init(int _n, int _w){ n = _n; w = _w; if(n==1 && w>1) w=IINF; rcnt.resize(n,0); ccnt.resize(n,0); } void setPos(int a, int i, int j){ pos[a] = {i,j}; } void mark(int a){ if(pos.count(a)==0)return; int i, j; i = pos[a].first; j = pos[a].second; rcnt[i]++; ccnt[j]++; if(i==j){ nnm[0]++; if(nnm[0]==n)ok++; } if(i==n-j-1){ nnm[1]++; if(nnm[1]==n)ok++; } if(rcnt[i]==n)ok++; if(ccnt[j]==n)ok++; } bool iswin(){ return ok>=w; } }; int main() { int n, u, v, m; cin >> n >> u >> v >> m; board usa, neko; usa.init(n,u); neko.init(n,v); REP(i,n)REP(j,n){ int a; cin >> a; usa.setPos(a,i,j); } REP(i,n)REP(j,n){ int a; cin >> a; neko.setPos(a,i,j); } string ans=""; REP(i,m){ int a; cin >> a; usa.mark(a); neko.mark(a); if(ans.size()==0){ if(usa.iswin() && !neko.iswin()){ ans = "USAGI"; } else if(!usa.iswin() && neko.iswin()){ ans = "NEKO"; } else if(usa.iswin() && neko.iswin()){ ans = "DRAW"; } } } if(ans.size()==0) ans = "DRAW"; cout << ans << endl; return 0; }
#include<iostream> #include<cstdio> #include<string> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> using namespace std; typedef long long ll; const ll MOD = 1000000007; const ll INF = (ll)1000000007 * 1000000007; const double EPS = 1e-9; typedef pair<int,int> P; typedef unsigned int ui; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; typedef complex<ld> Point; const ld eps = 1e-11; const ld pi = acos(-1.0); P bingo1[1000001]; P bingo2[1000001]; int app1[1000001] = {}; int app2[1000001] = {}; int main() { int n, u, v, m; cin >> n >> u >> v >> m; int h1[500] = {}; int w1[500] = {}; int c1[2] = {}; int c2[2] = {}; int h2[500] = {}; int w2[500] = {}; int x; rep(i, n) { rep(j, n) { cin >> x; bingo1[x] = { i,j }; app1[x] = 1; } } rep(i, n) { rep(j, n) { cin >> x; bingo2[x] = { i,j }; app2[x] = 1; } } int cnt1 = 0; int cnt2 = 0; bool f = false; if (n == 1) { rep(i, m) { cin >> x; if (f)continue; if (app1[x])cnt1++; if (app2[x])cnt2++; if (cnt1 >= u && cnt2 >= v) { cout << "DRAW" << endl; f = true; } else if (cnt1 >= u) { cout << "USAGI" << endl; f = true; } else if (cnt2 >= v) { cout << "NEKO" << endl; f = true; } } if (!f) { cout << "DRAW" << endl; } return 0; } rep(i, m) { cin >> x; if (f)continue; if (app1[x]) { int x1 = bingo1[x].first; int y1 = bingo1[x].second; h1[x1]++; if (h1[x1] == n)cnt1++; w1[y1]++; if (w1[y1] == n)cnt1++; if (x1 == y1) { c1[0]++; if (c1[0] == n)cnt1++; } if (x1 + y1 == n - 1) { c1[1]++; if (c1[1] == n)cnt1++; } } if (app2[x]) { int x2 = bingo2[x].first; int y2 = bingo2[x].second; h2[x2]++; if (h2[x2] == n)cnt2++; w2[y2]++; if (w2[y2] == n)cnt2++; if (x2 == y2) { c2[0]++; if (c2[0] == n)cnt2++; } if (x2 + y2 == n - 1) { c2[1]++; if (c2[1] == n)cnt2++; } } if (cnt1 >= u && cnt2 >= v) { cout << "DRAW" << endl; f = true; } else if (cnt1 >= u) { cout << "USAGI" << endl; f = true; } else if (cnt2 >= v) { cout << "NEKO" << endl; f = true; } } if (!f) { cout << "DRAW" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long // <-----!!!!!!!!!!!!!!!!!!! #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)-1;i>=0;i--) #define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl #define printVS(_vs) for(auto _x : _vs){cout << _x << endl;} #define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;} #define printP(_p) cout << _p.first << " " << _p.second << endl #define printVP(_vp) for(auto _p : _vp) printP(_p); typedef long long ll; typedef pair<int, int> Pii; typedef tuple<int, int, int> TUPLE; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vector<int>> Graph; const int inf = 1e9; const int mod = 1e9 + 7; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int n, m; vi u(2); cin >> n >> u[0] >> u[1] >> m; vector<map<int, Pii>> mp(2); rep(k, 2) rep(i, n) rep(j, n) { int p; cin >> p; mp[k][p] = Pii(i, j); } vvi row(2, vi(n, n)); vvi col(2, vi(n, n)); vi diag1(2, n); // x = y vi diag2(2, n); // x + y = n - 1 rep(i, m) { int p; cin >> p; rep(k, 2) { if (mp[k].count(p)) { int x, y; tie(x, y) = mp[k][p]; row[k][x]--; if (row[k][x] == 0) u[k]--; if (n == 1) continue; col[k][y]--; if (col[k][y] == 0) u[k]--; if (x == y) { diag1[k]--; if (diag1[k] == 0) u[k]--; } if (x + y == n - 1) { diag2[k]--; if (diag2[k] == 0) u[k]--; } } } if (u[0] <= 0 && u[1] > 0) { cout << "USAGI" << endl; return 0; } else if (u[0] > 0 && u[1] <= 0) { cout << "NEKO" << endl; return 0; } else if (u[0] < 0 && u[1] < 0) { cout << "DRAW" << endl; return 0; } } cout << "DRAW" << endl; }
#include <cstdio> #include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <climits> #include <cfloat> using namespace std; int main() { int n, m; vector<int> rest(2); cin >> n >> rest[0] >> rest[1] >> m; if(n == 1){ int a, b; cin >> a >> b; for(int i=0; i<m; ++i){ int x; cin >> x; if(x == a) -- rest[0]; if(x == b) -- rest[1]; if(rest[0] <= 0 || rest[1] <= 0){ if(rest[0] <= 0 && rest[1] <= 0) cout << "DRAW" << endl; else if(rest[0] <= 0) cout << "USAGI" << endl; else cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; } vector<vector<pair<int, int> > > p(2, vector<pair<int, int> >(1000001, make_pair(-1, -1))); for(int i=0; i<2; ++i){ for(int j=0; j<n; ++j){ for(int k=0; k<n; ++k){ int a; cin >> a; p[i][a] = make_pair(j, k); } } } vector<vector<int> > yNum(2, vector<int>(n, 0)), xNum(2, vector<int>(n, 0)), diagonalNum(2, vector<int>(2, 0)); for(int i=0; i<m; ++i){ int a; cin >> a; for(int i=0; i<2; ++i){ if(p[i][a].first != -1){ int y = p[i][a].first; int x = p[i][a].second; if(++ yNum[i][y] == n) -- rest[i]; if(++ xNum[i][x] == n) -- rest[i]; if(y == x && ++ diagonalNum[i][0] == n) -- rest[i]; if(y + x == n-1 && ++ diagonalNum[i][1] == n) -- rest[i]; } } if(rest[0] <= 0 || rest[1] <= 0){ if(rest[0] <= 0 && rest[1] <= 0) cout << "DRAW" << endl; else if(rest[0] <= 0) cout << "USAGI" << endl; else cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG_MODE #define DBG(n) n; #else #define DBG(n) ; #endif #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define PB push_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;} #define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;} #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 1000000007 typedef long long ll; typedef pair<ll,ll> P; pair<int,int> usa[1111111]; pair<int,int> neko[1111111]; int sumusa[2222]; int sumneko[2222]; int usascore,nekoscore; int N,U,V,M; int main(){ cin >> N >> U >> V >> M; REP(i,N){ REP(j,N){ int tmp;cin >> tmp; usa[tmp] = MP(i+1,j+1); } } REP(i,N){ REP(j,N){ int tmp;cin >> tmp; neko[tmp] = MP(i+1,j+1); } } REP(i,M){ int tmp;cin >> tmp; if(N == 1){ int us = usa[tmp].FI != 0; int ne = neko[tmp].FI != 0; if(us >= U && ne < V){ cout << "USAGI" << endl; return 0; } if(us < U && ne >= V){ cout << "NEKO" << endl; return 0; } } else { if(usa[tmp].FI != 0){ sumusa[usa[tmp].FI]++; if(sumusa[usa[tmp].FI] == N){ usascore++; } sumusa[555+usa[tmp].SE]++; if(sumusa[555+usa[tmp].SE] == N){ usascore++; } if(usa[tmp].FI == usa[tmp].SE){ sumusa[1111]++; if(sumusa[1111] == N)usascore++; } if(usa[tmp].FI == (N - usa[tmp].SE + 1)){ sumusa[1119]++; if(sumusa[1119] == N)usascore++; } } if(neko[tmp].FI != 0){ sumneko[neko[tmp].FI]++; if(sumneko[neko[tmp].FI] == N){ nekoscore++; } sumneko[555+neko[tmp].SE]++; if(sumneko[555+neko[tmp].SE] == N){ nekoscore++; } if(neko[tmp].FI == neko[tmp].SE){ sumneko[1111]++; if(sumneko[1111] == N)nekoscore++; } if(neko[tmp].FI == (N - neko[tmp].SE + 1)){ sumneko[1119]++; if(sumneko[1119] == N)nekoscore++; } } if(usascore >= U && nekoscore < V){ cout << "USAGI" << endl; return 0; } if(usascore < U && nekoscore >= V){ cout << "NEKO" << endl; return 0; } } } cout << "DRAW" << endl; return 0; }
#define _USE_MATH_DEFINES #include <iostream> #include <fstream> #include <sstream> #include <string> #include <cstring> #include <vector> #include <set> #include <map> #include <unordered_map> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include <numeric> #include <functional> #include <cctype> #include <list> #include <limits> #include <cassert> //#include <boost/multiprecision/cpp_int.hpp> using namespace std; using Int = long long; //using namespace boost::multiprecision; const double EPS = (1e-10); long long const MOD = 1000000007; long long mod_pow(long long x, long long n) { long long res = 1; for(int i = 0;i < 60; i++){ if(n >> i & 1) res = res * x % MOD; x = x * x % MOD; } return res; } template<typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; } template<typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } void fastInput() { cin.tie(0); ios::sync_with_stdio(false); } int main(void) { int N, U, V, M; cin >> N >> U >> V >> M; map<int, pair<int, int>> rabbitM; map<int, pair<int, int>> catM; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { int tmp; cin >> tmp; rabbitM[tmp] = {i, j}; } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { int tmp; cin >> tmp; catM[tmp] = {i, j}; } } vector<int> rabbitY(N); vector<int> rabbitX(N); vector<int> rabbitNaname(2); vector<int> catY(N); vector<int> catX(N); vector<int> catNaname(2); int flag = 0; if (N == 1) { U *= 4; V *= 4; } for (int i = 0; i < M; i++) { int card; cin >> card; if (rabbitM.count(card)) { pair<int, int> p = rabbitM[card]; rabbitY[p.first]++; rabbitX[p.second]++; int fR[2] = {0}; if (p.first + p.second == N-1) { rabbitNaname[0]++; fR[0] = 1; } if (p.first + (N-1-p.second) == N-1) { rabbitNaname[1]++; fR[1] = 1; } if (rabbitY[p.first] == N) U--; if (rabbitX[p.second] == N) U--; if (rabbitNaname[0] == N && fR[0]) U--; if (rabbitNaname[1] == N && fR[1]) U--; } if (catM.count(card)) { pair<int, int> p = catM[card]; catY[p.first]++; catX[p.second]++; int fC[2] = {0}; if (p.first + p.second == N-1) { catNaname[0]++; fC[0] = 1; } if (p.first + (N-1-p.second) == N-1) { catNaname[1]++; fC[1] = 1; } if (catY[p.first] == N) V--; if (catX[p.second] == N) V--; if (catNaname[0] == N && fC[0]) V--; if (catNaname[1] == N && fC[1]) V--; } if (U <= 0 && 0 < V) { flag = 1; break; } else if (0 < U && V <= 0) { flag = 2; break; } } if (flag == 1) { cout << "USAGI" << endl; } else if (flag == 2) { cout << "NEKO" << endl; } else { cout << "DRAW" << endl; } return 0; }
#include <set> #include <cstring> #include <cstdio> #include <cstring> #include <cstdlib> #include <cctype> #include <unistd.h> #define REP(i,n) for(int i=0; i<(int)(n); i++) char buffer[1024 * 1024]; int pos = 0; int end = 0; inline int mygetchar(){ if(pos == end){ end = read(0, buffer, sizeof(buffer)); pos = 0; } return buffer[pos++]; } __attribute__((always_inline)) int getInt(){ int ret = 0, c; c = mygetchar(); while(!isdigit(c)) c = mygetchar(); while(isdigit(c)){ ret *= 10; ret += c - '0'; c = mygetchar(); } return ret; } using namespace std; int ux[1000001]; int uy[1000001]; int ucntyoko[500]; int ucnttate[500]; int ucntnaname[2]; int nx[1000001]; int ny[1000001]; int ncntyoko[500]; int ncnttate[500]; int ncntnaname[2]; int main(){ int n = getInt(); int u = getInt(); int v = getInt(); int m = getInt(); memset(ux, -1, sizeof(ux)); memset(uy, -1, sizeof(uy)); memset(nx, -1, sizeof(nx)); memset(ny, -1, sizeof(ny)); REP(i,n) REP(j,n){ int t = getInt(); ux[t] = j; uy[t] = i; } REP(i,n) REP(j,n){ int t = getInt(); nx[t] = j; ny[t] = i; } int uans = 0; int nans = 0; REP(i,m){ int t = getInt(); if(ux[t] != -1){ if(++ucnttate[uy[t]] == n) uans++; if(++ucntyoko[ux[t]] == n) uans++; if(ux[t] == uy[t]) if(++ucntnaname[0] == n) uans++; if(ux[t] == n - 1 - uy[t]) if(++ucntnaname[1] == n) uans++; } if(nx[t] != -1){ if(++ncnttate[ny[t]] == n) nans++; if(++ncntyoko[nx[t]] == n) nans++; if(nx[t] == ny[t]) if(++ncntnaname[0] == n) nans++; if(nx[t] == n - 1 - ny[t]) if(++ncntnaname[1] == n) nans++; } if(n == 1){ nans = min(1, nans); uans = min(1, uans); } if(uans >= u && nans >= v){ puts("DRAW"); return 0; }else if(uans >= u){ puts("USAGI"); return 0; }else if(nans >= v){ puts("NEKO"); return 0; } } puts("DRAW"); return 0; }
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) using namespace std; typedef pair<int, int> P; int a[510][510], b[510][510]; int c[100010]; map<int, P> ma, mb; int ya[510], xa[510], yb[510], xb[510]; int cra, crb, ccra, ccrb; int counta, countb; int main(){ int n, u, v, m; cin >> n >> u >> v >> m; rep(i, 0, n){ rep(j, 0, n){ cin >> a[i][j]; ma[a[i][j]] = {i, j}; } } rep(i, 0, n){ rep(j, 0, n){ cin >> b[i][j]; mb[b[i][j]] = {i, j}; } } rep(i, 0, m){ cin >> c[i]; } if(n == 1){ rep(i, 0, m){ if(ma.count(c[i])) counta++; if(mb.count(c[i])) countb++; if(counta == u && countb < v){ cout << "USAGI" << endl; return 0; } if(counta < u && countb == v){ cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; } rep(i, 0, m){ if(ma.count(c[i])){ int y = ma[c[i]].first; int x = ma[c[i]].second; ya[y]++; xa[x]++; if(y == x) cra++; if(y + x == n - 1) ccra++; if(ya[y] == n) counta++; if(xa[x] == n) counta++; if(y == x && cra == n) counta++; if(y + x == n - 1 && ccra == n) counta++; } if(mb.count(c[i])){ int y = mb[c[i]].first; int x = mb[c[i]].second; yb[y]++; xb[x]++; if(y == x) crb++; if(y + x == n - 1) ccrb++; if(yb[y] == n) countb++; if(xb[x] == n) countb++; if(y == x && crb == n) countb++; if(y + x == n - 1 && ccrb == n) countb++; } // cout << counta << ' ' << countb << endl; if(counta >= u && countb < v){ cout << "USAGI" << endl; return 0; } if(counta < u && countb >= v){ cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; }
#include <iostream> #include <vector> #include <map> using namespace std; int n; void make_map(map<int,int>& col, map<int,int>& row, map<int,bool>& dia, map<int,bool>& rdia) { int temp; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> temp; col[temp] = j + 1; row[temp] = i + 1; if (i == j) { dia[temp] = true; } if (i+j == n-1) { rdia[temp] = true; } } } } int main(void) { int u,v,m; cin >> n >> u >> v >> m; map<int,int> rcol,ccol; map<int,int> rrow,crow; map<int,bool> rdia,cdia; map<int,bool> rrdia,crdia; int temp; if (n > 1) { make_map(rcol,rrow,rdia,rrdia); make_map(ccol,crow,cdia,crdia); /* for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> temp; rcol[temp] = j + 1; rrow[temp] = i + 1; if (i == j) { rdia[temp] = true; } if (i+j == n-1) { rrdia[temp] = true; } } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> temp; ccol[temp] = j + 1; crow[temp] = i + 1; if (i == j) { cdia[temp] = true; } if (i+j == n-1) { crdia[temp] = true; } } } */ } else { cin >> temp; rdia[temp] = true; cin >> temp; cdia[temp] = true; } int card,rc,cc; vector<int> rc_col(n,0),cc_col(n,0); vector<int> rc_row(n,0),cc_row(n,0); vector<int> rc_dia(2,0),cc_dia(2,0); rc = cc = 0; bool fin = false; for (int i = 0; i < m; ++i) { cin >> card; if (!fin) { if (rcol[card] > 0) { ++rc_col[rcol[card]-1]; if (rc_col[rcol[card]-1] == n) { ++rc; } } if (rrow[card] > 0) { ++rc_row[rrow[card]-1]; if (rc_row[rrow[card]-1] == n) { ++rc; } } if (rdia[card]) { ++rc_dia[0]; if (rc_dia[0] == n) { ++rc; } } if (rrdia[card]) { ++rc_dia[1]; if (rc_dia[1] == n) { ++rc; } } if (ccol[card] > 0) { ++cc_col[ccol[card]-1]; if (cc_col[ccol[card]-1] == n) { ++cc; } } if (crow[card] > 0) { ++cc_row[crow[card]-1]; if (cc_row[crow[card]-1] == n) { ++cc; } } if (cdia[card]) { ++cc_dia[0]; if (cc_dia[0] == n) { ++cc; } } if (crdia[card]) { ++cc_dia[1]; if (cc_dia[1] == n) { ++cc; } } if (rc >= u && cc >= v) { cout << "DRAW" << endl; fin = true; } else if (rc >= u) { cout << "USAGI" << endl; fin = true; } else if (cc >= v) { cout << "NEKO" << endl; fin = true; } } } if (!fin) { cout << "DRAW" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,u,v,m; cin>>n>>u>>v>>m; map<int,pair<int,int>> usagi; map<int,pair<int,int>> neko; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int val; cin>>val; usagi[val]=make_pair(i,j); } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int val; cin>>val; neko[val]=make_pair(i,j); } } vector<int> usagirow(n,0); vector<int> usagicol(n,0); int usagidig0=0,usagidig1=0; int usagingo=0; vector<int> nekorow(n,0); vector<int> nekocol(n,0); int nekodig0=0,nekodig1=0; int nekongo=0; const int DRAW=-1; const int USAGI=0; const int NEKO=1; int winner=DRAW; for(int i=0;i<m;i++){ int val; cin>>val; if(n==1){ if(neko.count(val)) nekongo++; if(usagi.count(val)) usagingo++; } else{ if(neko.count(val)){ int r=neko[val].first,w=neko[val].second; if(++nekorow[r]==n) nekongo++; if(++nekocol[w]==n) nekongo++; if(r==w){ if(++nekodig0==n) nekongo++; } if(r+w==n-1){ if(++nekodig1==n) nekongo++; } } if(usagi.count(val)){ int r=usagi[val].first,w=usagi[val].second; if(++usagirow[r]==n) usagingo++; if(++usagicol[w]==n) usagingo++; if(r==w){ if(++usagidig0==n) usagingo++; } if(r+w==n-1){ if(++usagidig1==n) usagingo++; } } } bool uw=(usagingo>=u); bool nw=(nekongo>=v); if(uw ^ nw){ if(uw) winner=USAGI; if(nw) winner=NEKO; } } if(winner==USAGI) cout<<"USAGI"<<endl; if(winner==NEKO) cout<<"NEKO"<<endl; if(winner==DRAW) cout<<"DRAW"<<endl; return 0; }
#include <iostream> #include <vector> #include <cstring> #include <string> #include <algorithm> #include <iomanip> using namespace std; int n, u, v, m; int card[100000]; int row[2][1000010], col[2][1000010]; int board[2][500][500]; int rem[2]; int row_n[2][500], col_n[2][500], crs_n[2][2]; void solve() { for(int loop = 0; loop < m; loop++) { int c = card[loop]; for(int i = 0; i < 2; i++) { if(row[i][c] == -1) continue; row_n[i][row[i][c]]--; if(row_n[i][row[i][c]] == 0) rem[i]--; col_n[i][col[i][c]]--; if(col_n[i][col[i][c]] == 0) rem[i]--; if(row[i][c] == col[i][c]) { crs_n[i][0]--; if(crs_n[i][0] == 0) rem[i]--; } if(row[i][c] == n - 1 - col[i][c]) { crs_n[i][1]--; if(crs_n[i][1] == 0) rem[i]--; } } if(rem[0] <= 0 && rem[1] > 0) { cout << "USAGI" << endl; return; } if(rem[0] > 0 && rem[1] <= 0) { cout << "NEKO" << endl; return; } if(rem[0] <= 0 && rem[1] <= 0) { cout << "DRAW" << endl; return; } } cout << "DRAW" << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> rem[0] >> rem[1] >> m; fill((int*)begin(row), (int*)end(row), -1); fill((int*)begin(col), (int*)end(col), -1); for(int i = 0; i < 2; i++) { for(int j = 0; j < n; j++) { for(int k = 0; k < n; k++) { cin >> board[i][j][k]; row[i][board[i][j][k]] = j; col[i][board[i][j][k]] = k; } } } for(int i = 0; i < 2; i++) { for(int j = 0; j < n; j++) { row_n[i][j] = n; if(n != 1) col_n[i][j] = n; } for(int j = 0; j < 2; j++) { if(n != 1) crs_n[i][j] = n; } } for(int i = 0; i < m; i++) { cin >> card[i]; } solve(); }
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <string> #include <vector> #include <queue> #include <map> #include <set> #include <algorithm> #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) #define sz size() #define pb push_back #define mp make_pair #define ALL(X) (X).begin(),(X).end() using namespace std; const int INF = 1000000000; const double eps = 1e-8; int main(void) { int n,u,v,m; cin>>n>>u>>v>>m; map<int,pair<int,int>> Usagi; map<int,pair<int,int>> Neko; REP(i,n)REP(j,n){ int l; cin>>l; Usagi[l]=mp(i,j); } REP(i,n)REP(j,n){ int l; cin>>l; Neko[l]=mp(i,j); } vector<int> Us(2*n+2,0); vector<int> Nk(2*n+2,0); int Us_cnt = 0; int Nk_cnt = 0; bool f=true; REP(i,m){ int l;cin>>l; if(Usagi.find(l)!=Usagi.end()){ auto p=Usagi[l]; if(++Us[p.first] == n) Us_cnt++; if(++Us[n+p.second]==n) Us_cnt++; if(p.first==p.second) if(++Us[2*n]==n) Us_cnt++; if((p.first+p.second)==(n-1)) if(++Us[2*n+1]==n) Us_cnt++; } if(Neko.find(l)!=Neko.end()){ auto p=Neko[l]; if(++Nk[p.first] == n) Nk_cnt++; if(++Nk[n+p.second]==n) Nk_cnt++; if(p.first==p.second) if(++Nk[2*n]==n) Nk_cnt++; if((p.first+p.second)==(n-1)) if(++Nk[2*n+1]==n) Nk_cnt++; } if((Us_cnt>=u&&n>1) || (Us_cnt>=1&&u==n&&n==1)){ if((Nk_cnt>=v&&n>1)||(Nk_cnt>=1&&v==n&&n==1)){ cout<<"DRAW"<<endl; }else{ cout<<"USAGI"<<endl; } f=false; break; }else if((Nk_cnt>=v&&n>1)||(Nk_cnt>=1&&v==n&&n==1)){ cout<<"NEKO"<<endl; f=false; break; } } if(f) cout<<"DRAW"<<endl; return 0; }
#include <cstdio> #include <cstring> int n,u,v,m; int fie[2][501][501]; bool ok[2][501][501]; int card[100001]; int wx[2][1000001],wy[2][1000001]; int cnt[2]; int linex[2][501],liney[2][501],cross[2][2]; bool checkx(int v,int x){ for(int i=0;i<n;i++){ if(!ok[v][x][i])return false; } return true; } bool checky(int v,int y){ for(int i=0;i<n;i++){ if(!ok[v][i][y])return false; } return true; } bool checkc(int v,int dir){ if(dir==0){ for(int i=0;i<n;i++){ if(!ok[v][i][i])return false; } }else{ for(int i=0;i<n;i++){ if(!ok[v][i][n-i-1])return false; } } return true; } int main(void){ scanf("%d %d %d %d",&n,&u,&v,&m); if(n==1){ u*=4; v*=4; } memset(wx,-1,sizeof(wx)); memset(wy,-1,sizeof(wy)); for(int i=0;i<2;i++){ for(int j=0;j<n;j++){ for(int k=0;k<n;k++){ scanf("%d",&fie[i][k][j]); wx[i][fie[i][k][j]]=k; wy[i][fie[i][k][j]]=j; } } } for(int i=0;i<m;i++){ scanf("%d",&card[i]); } for(int i=0;i<m;i++){ for(int j=0;j<2;j++){ if(wx[j][card[i]]!=-1){ ok[j][wx[j][card[i]]][wy[j][card[i]]]=true; if(!linex[j][wx[j][card[i]]]){ if(checkx(j,wx[j][card[i]])){ linex[j][wx[j][card[i]]]=true; cnt[j]++; } } if(!liney[j][wy[j][card[i]]]){ if(checky(j,wy[j][card[i]])){ liney[j][wy[j][card[i]]]=true; cnt[j]++; } } if(wy[j][card[i]]==wx[j][card[i]]){ if(!cross[j][0] && checkc(j,0)){ cross[j][0]=true; cnt[j]++; } } if(wy[j][card[i]]==n-wx[j][card[i]]-1){ if(!cross[j][1] && checkc(j,1)){ cross[j][1]=true; cnt[j]++; } } } } //printf("%d %d\n",cnt[0],cnt[1]); if(cnt[0]>=u && cnt[1]>=v){ printf("DRAW\n"); return 0; } if(cnt[0]>=u){ printf("USAGI\n"); return 0; } if(cnt[1]>=v){ printf("NEKO\n"); return 0; } } printf("DRAW\n"); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); i++) #define repp(i, l, r) for(int i = (l); i < (r); i++) #define per(i, n) for(int i = ((n)-1); i >= 0; i--) #define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(),(x).end() #define MOD 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP <<" "<< #define CYES cout<<"Yes"<<endl #define CNO cout<<"No"<<endl #define CFS cin.tie(0);ios::sync_with_stdio(false) typedef long long LL; typedef long double LD; vector<int> vx={-1,-1,0,1}; vector<int> vy={0,1,1,1}; vector<vector<bool>> cha,chb; int ap=0,bp=0; void ren(int x, int y, vector<vector<bool>> &v, vector<vector<bool>> &ch, int &p){ rep(i,4){ int tmp=-1; int nx = x, ny = y; while(0<=nx&&nx<v.size()&&0<=ny&&ny<v.size()){ if(!v[nx][ny]) break; tmp++; nx+=vx[i]; ny+=vy[i]; } nx = x, ny = y; while(0<=nx&&nx<v.size()&&0<=ny&&ny<v.size()){ if(!v[nx][ny]) break; tmp++; nx-=vx[i]; ny-=vy[i]; } if(tmp==v.size()){ if(i==0){ if(!ch[i][y]) ch[i][y]=true,p++; }else if(i==1){ if(!ch[i][0]) ch[i][0]=true,p++; }else if(i==2){ if(!ch[i][x]) ch[i][x]=true,p++; }else{ if(!ch[i][0]) ch[i][0]=true,p++; } } } return; } struct check{ int x; int y; int p; check(int xx, int yy, int pp) : x(xx),y(yy),p(pp){} }; int main(){ int n,u,v,m; cin >> n >> u >> v >> m; if(n==1){ int x,y; cin >> x >> y; int a=0,b=0; bool usa=false,neko=false; int c; rep(i,m){ cin >> c; if(x==c){ if(a==0) a++; if(a>=u) usa=true; } if(y==c){ if(b==0) b++; if(b>=v) neko=true; } if(usa||neko) break; } if(usa){ if(neko){ cout << "DRAW" << endl; }else{ cout << "USAGI" << endl; } }else{ if(neko){ cout << "NEKO" << endl; }else{ cout << "DRAW" << endl; } } return 0; } vector<vector<bool>> a(n,vector<bool>(n,false)),b(n,vector<bool>(n,false)); map<int,vector<check>> mp; int x; rep(i,n){ rep(j,n){ cin >> x; mp[x].push_back(check(i,j,0)); } } rep(i,n){ rep(j,n){ cin >> x; mp[x].push_back(check(i,j,1)); } } bool usa=false,neko=false; cha=vector<vector<bool>>(4,vector<bool>(n)); chb=vector<vector<bool>>(4,vector<bool>(n)); rep(t,m){ cin >> x; for(auto &c:mp[x]){ if(c.p==0){ a[c.x][c.y]=true; ren(c.x,c.y,a,cha,ap); if(ap>=u){ usa=true; } }else{ b[c.x][c.y]=true; ren(c.x,c.y,b,chb,bp); if(bp>=v){ neko=true; } } } if(usa){ if(neko){ cout << "DRAW" << endl; return 0; }else{ cout << "USAGI" << endl; return 0; } }else{ if(neko){ cout << "NEKO" << endl; return 0; } } } cout << "DRAW" << endl; return 0; }
#include <iostream> #include <map> using namespace std; typedef pair<int,int> P; int N,U,V,M; int card[100010]; int USAGI[510][510],NEKO[510][510]; int main(){ cin >> N >> U >> V >> M; map<int,P> usagi,neko; for(int i=1;i<=N;i++){ for(int j=1;j<=N;j++){ cin >> USAGI[i][j]; usagi[USAGI[i][j]] = {i,j}; } } for(int i=1;i<=N;i++){ for(int j=1;j<=N;j++){ cin >> NEKO[i][j]; neko[NEKO[i][j]] = {i,j}; } } for(int i=1;i<=M;i++) cin >> card[i]; int res_usagi = 0,res_neko = 0; if(N==1){ for(int i=1;i<=M;i++){ if(usagi.count(card[i])) res_usagi++; if(neko.count(card[i])) res_neko++; if(res_usagi>=U && res_neko<V){ cout << "USAGI" << endl; return 0; } if(res_usagi<U && res_neko>=V){ cout << "NEKO" << endl; return 0; } if(res_usagi>=U && res_neko>=V){ cout << "DRAW" << endl; return 0; } } cout << "DRAW" << endl; return 0; } map<int,int> c_usagi[4],c_neko[4]; for(int i=1;i<=M;i++){ if(usagi.count(card[i])){ P u = usagi[card[i]]; c_usagi[0][u.first]++; c_usagi[1][u.second]++; c_usagi[2][u.first+u.second]++; c_usagi[3][u.first-u.second]++; if(c_usagi[0][u.first]==N){ res_usagi++; c_usagi[0][u.first] = 0; } if(c_usagi[1][u.second]==N){ res_usagi++; c_usagi[1][u.second] = 0; } if(c_usagi[2][u.first+u.second]==N){ res_usagi++; c_usagi[2][u.first+u.second] = 0; } if(c_usagi[3][u.first-u.second]==N){ res_usagi++; c_usagi[3][u.first-u.second] = 0; } } if(neko.count(card[i])){ P v = neko[card[i]]; c_neko[0][v.first]++; c_neko[1][v.second]++; c_neko[2][v.first+v.second]++; c_neko[3][v.first-v.second]++; if(c_neko[0][v.first]==N){ res_neko++; c_neko[0][v.first] = 0; } if(c_neko[1][v.second]==N){ res_neko++; c_neko[1][v.second] = 0; } if(c_neko[2][v.first+v.second]==N){ res_neko++; c_neko[2][v.first+v.second] = 0; } if(c_neko[3][v.first-v.second]==N){ res_neko++; c_neko[3][v.first-v.second] = 0; } } if(res_usagi>=U && res_neko<V){ cout << "USAGI" << endl; return 0; } if(res_usagi<U && res_neko>=V){ cout << "NEKO" << endl; return 0; } if(res_usagi>=U && res_neko>=V){ cout << "DRAW" << endl; return 0; } } cout << "DRAW" << endl; }
#include <stdio.h> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> #include <numeric> #include <cctype> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n, u, v, m; cin >> n >> u >> v >> m; map<int, pair<int, int>> up, vp; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int x; cin >> x; up[x] = { i,j }; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int x; cin >> x; vp[x] = { i,j }; } } vector<int> uv(n), uc(n), vv(n), vc(n); int u1 = 0, u2 = 0, v1 = 0, v2 = 0; int ucnt = 0, vcnt = 0; for (int i = 0; i < m; i++) { int x; cin >> x; if (up.count(x)) { int h, w; tie(h, w) = up[x]; uv[h]++; if (uv[h] == n) ucnt++; uc[w]++; if (uc[w] == n) ucnt++; if (h == w) { u1++; if (u1 == n) ucnt++; } if (h + w == n - 1) { u2++; if (u2 == n) ucnt++; } } if (vp.count(x)) { int h, w; tie(h, w) = vp[x]; vv[h]++; if (vv[h] == n) vcnt++; vc[w]++; if (vc[w] == n) vcnt++; if (h == w) {v1++; if (v1 == n) vcnt++; } if (h + w == n - 1) { v2++; if (v2 == n) vcnt++; } } if (n == 1) chmin(ucnt, 1), chmin(vcnt, 1); if (ucnt >= u and vcnt >= v) { cout << "DRAW" << endl; return 0; } else if (ucnt >= u) { cout << "USAGI" << endl; return 0; } else if (vcnt >= v) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; int field[2][550][550]; int column[2][550]; int row[2][550]; int cross[2][2]; int win[2]; map<int, i_i> mp[2]; int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> win[0] >> win[1] >> m; for(int i = 0; i <= 1; i++) { for(int y = 1; y <= n; y++) { for(int x = 1; x <= n; x++) { cin >> field[i][x][y]; mp[i][field[i][x][y]] = {x, y}; } } } bool end = false; while(m--) { int val; cin >> val; for(int index = 0; index <= 1; index++) { if(mp[index][val].first == 0) continue; int x = mp[index][val].first; int y = mp[index][val].second; column[index][x]++; row[index][y]++; if(column[index][x] == n) win[index]--; if(row[index][y] == n) { if(n >= 2) win[index]--; } if(x == y) { cross[index][0]++; if(cross[index][0] == n && n >= 2) win[index]--; } if(x + y == n + 1) { cross[index][1]++; if(cross[index][1] == n && n >= 2) win[index]--; } } //cerr << val << " " << win[0] << " " << win[1] << endl; if(win[1] <= 0 && win[0] > 0) { end = true; cout << "NEKO" << endl; break; } if(win[0] <= 0 && win[1] > 0) { end = true; cout << "USAGI" << endl; break; } } if(!end) cout << "DRAW" << endl; return 0; }
#include <iostream> #include <vector> #include <map> using namespace std; int n,card; void make_map(map<int,int>& col, map<int,int>& row, map<int,int>& dia, map<int,int>& rdia) { int temp; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> temp; col[temp] = j + 1; row[temp] = i + 1; if (i == j) { dia[temp] = n+1; } if (i+j == n-1) { rdia[temp] = n+2; } } } } bool check_line(int& count, map<int,int>& hash) { if (hash[card] > 0) { ++count; if (count == n) { return true; } } return false; } int main(void) { int u,v,m; cin >> n >> u >> v >> m; map<int,int> rcol,ccol; map<int,int> rrow,crow; map<int,int> rdia,cdia; map<int,int> rrdia,crdia; if (n > 1) { make_map(rcol,rrow,rdia,rrdia); make_map(ccol,crow,cdia,crdia); } else { int temp; cin >> temp; rdia[temp] = 1; cin >> temp; cdia[temp] = 1; } int rc,cc; vector<int> rc_col(n,0),cc_col(n,0); vector<int> rc_row(n,0),cc_row(n,0); vector<int> rc_dia(2,0),cc_dia(2,0); rc = cc = 0; bool fin = false; for (int i = 0; i < m; ++i) { cin >> card; if (!fin) { if (check_line(rc_col[rcol[card]-1],rcol)) { ++rc; } if (check_line(rc_row[rrow[card]-1],rrow)) { ++rc; } if (check_line(rc_dia[0],rdia)) { ++rc; } if (check_line(rc_dia[1],rrdia)) { ++rc; } if (check_line(cc_col[ccol[card]-1],ccol)) { ++cc; } if (check_line(cc_row[crow[card]-1],crow)) { ++cc; } if (check_line(cc_dia[0],cdia)) { ++cc; } if (check_line(cc_dia[1],crdia)) { ++cc; } /* if (rcol[card] > 0) { ++rc_col[rcol[card]-1]; if (rc_col[rcol[card]-1] == n) { ++rc; } } if (rrow[card] > 0) { ++rc_row[rrow[card]-1]; if (rc_row[rrow[card]-1] == n) { ++rc; } } if (rdia[card]) { ++rc_dia[0]; if (rc_dia[0] == n) { ++rc; } } if (rrdia[card]) { ++rc_dia[1]; if (rc_dia[1] == n) { ++rc; } } if (ccol[card] > 0) { ++cc_col[ccol[card]-1]; if (cc_col[ccol[card]-1] == n) { ++cc; } } if (crow[card] > 0) { ++cc_row[crow[card]-1]; if (cc_row[crow[card]-1] == n) { ++cc; } } if (cdia[card]) { ++cc_dia[0]; if (cc_dia[0] == n) { ++cc; } } if (crdia[card]) { ++cc_dia[1]; if (cc_dia[1] == n) { ++cc; } } */ if (rc >= u && cc >= v) { cout << "DRAW" << endl; fin = true; } else if (rc >= u) { cout << "USAGI" << endl; fin = true; } else if (cc >= v) { cout << "NEKO" << endl; fin = true; } } } if (!fin) { cout << "DRAW" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define all(v) (v).begin(),(v).end() #define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) #define pb push_back #define fi first #define se second template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;} template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;} struct F{ int U; int N; vector<vint>A; vint R,C; vpint la; int dgn,dgn2; int sc; void init(int n,int u,vector<vint>a){ N=n;U=u;A=a; R=C=vint(N); la=vpint(1000000,{-1,-1}); rep(i,N)rep(j,N){ a[i][j]--; la[a[i][j]]={i,j}; } sc=dgn=dgn2=0; } void add(int n){ n--; if(la[n].fi==-1)return; int y,x; tie(y,x)=la[n]; if(++R[y]==N)sc++; if(++C[x]==N)sc++; if(y==x&&(++dgn==N))sc++; if(N-1-y==x&&(++dgn2==N))sc++; } bool ok(){ if(N==1)return min(1ll,sc)>=U; return sc>=U; } }; signed main(){ int N,u,v,m; cin>>N>>u>>v>>m; vector<vint>A(N,vint(N)); rep(i,N)rep(j,N)cin>>A[i][j]; F usa;usa.init(N,u,A); rep(i,N)rep(j,N)cin>>A[i][j]; F neko;neko.init(N,v,A); vint qs(m); rep(i,m)cin>>qs[i]; rep(i,m){ usa.add(qs[i]); neko.add(qs[i]); if(usa.ok()&&neko.ok()){ cout<<"DRAW"<<endl; return 0; } if(usa.ok()){ cout<<"USAGI"<<endl; return 0; } if(neko.ok()){ cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false), cin.tie(0); int n, u, v, m; cin >> n >> u >> v >> m; unordered_map<int, pair<int, int>> a, b; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int val; cin >> val; a[val] = make_pair(i, j); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int val; cin >> val; b[val] = make_pair(i, j); } } vector<int> r1(n), r2(n), c1(n), c2(n); int na1 = 0, na2 = 0, ne1 = 0, ne2 = 0; int cnt1 = 0, cnt2 = 0; int res = 0; bool end = false; for (int i = 0; i < m; i++) { int val; cin >> val; if (!res && a.count(val)) { int x, y; tie(x, y) = a[val]; ++r1[x]; if (r1[x] == n) ++cnt1; ++c1[y]; if (n > 1 && c1[y] == n) ++cnt1; if (n > 1 && x == y) { ++na1; if (na1 == n) ++cnt1; } if (n > 1 && x + y == n - 1) { ++ne1; if (ne1 == n) ++cnt1; } } if (!res && b.count(val)) { int x, y; tie(x, y) = b[val]; ++r2[x]; if (r2[x] == n) ++cnt2; ++c2[y]; if (n > 1 && c2[y] == n) ++cnt2; if (n > 1 && x == y) { ++na2; if (na2 == n) ++cnt2; } if (n > 1 && x + y == n - 1) { ++ne2; if (ne2 == n) ++cnt2; } } if (end) continue; if (cnt1 >= u && cnt2 >= v) { end = true; } else if (cnt1 >= u) { res = 1; end = true; } else if (cnt2 >= v) { res = -1; end = true; } } puts(res == 0 ? "DRAW" : res > 0 ? "USAGI" : "NEKO"); return 0; }
#include <iostream> #include <map> #define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++) using namespace std; typedef pair<int, int> pii; int N, U[2], M, A, C[100000]; map<int, pii> P[2]; int main(void) { cin >> N >> U[0] >> U[1] >> M; REP(i, 0, 2) REP(j, 0, N) REP(k, 0, N) { cin >> A; P[i][A] = pii(j, k); } REP(i, 0, M) cin >> C[i]; int ans = -1; int cnt[2] = { 0, 0 }; if(N == 1) { REP(i, 0, M) { bool b[2] = { false, false }; REP(t, 0, 2) if(P[t].count(C[i])) { cnt[t]++; if(cnt[t] == U[t]) b[t] = true; } if(b[0] || b[1]) { if(b[0] && !b[1]) ans = 0; if(!b[0] && b[1]) ans = 1; if(b[0] && b[1]) ans = -1; break; } } } else { int v[2][500], h[2][500], c1[2] = { 0, 0 }, c2[2] = { 0, 0 }; REP(i, 0, 2) REP(j, 0, N) h[i][j] = v[i][j] = 0; REP(i, 0, M) { bool b[2] = { false, false }; REP(t, 0, 2) if(P[t].count(C[i])) { int y = P[t][C[i]].first, x = P[t][C[i]].second; if(++v[t][y] == N) cnt[t]++; if(++h[t][x] == N) cnt[t]++; if(x == y && ++c1[t] == N) cnt[t]++; if(N - x - 1 == y && ++c2[t] == N) cnt[t]++; if(cnt[t] >= U[t]) b[t] = true; } if(b[0] || b[1]) { if(b[0] && !b[1]) ans = 0; if(!b[0] && b[1]) ans = 1; if(b[0] && b[1]) ans = -1; break; } } } cout << (ans == -1 ? "DRAW" : ans == 0 ? "USAGI" : "NEKO") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using vi=vector<int>; using vvi=vector<vi>; using vs=vector<string>; using msi=map<string,int>; using mii=map<int,int>; using pii=pair<int,int>; using vlai=valarray<int>; using ll=long long; #define rep(i,n) for(int i=0;i<n;i++) #define range(i,s,n) for(int i=s;i<n;i++) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define fs first #define sc second #define pb push_back #define eb emplace_back #define mp make_pair #define INF 1e9 #define EPS 1e-9 using vd=vector<double>; using vvd=vector<vd>; int main(){ int n,m; vi tg(2); cin>>n>>tg[0]>>tg[1]>>m; vector<vvi> line(2,vvi(2,vi(n,0))); //0:usagi,1:neko. 0:tate,1:yoko vvi naname(2,vi(2,0)); vector<vector<pii>> card(2,vector<pii>(1000001,mp(-1,-1))); rep(pl,2)rep(i,n)rep(j,n){ int num;cin>>num; card[pl][num]=mp(i,j); } vi bingo(2,0); int stat=0; rep(lp,m){ int num;cin>>num; stat=0; rep(pl,2){ int y=card[pl][num].fs; int x=card[pl][num].sc; if(y==-1)continue; line[pl][0][x]++; line[pl][1][y]++; if(x==y){naname[pl][0]++; if(naname[pl][0]==n)bingo[pl]++;} if(x+y+1==n){naname[pl][1]++; if(naname[pl][1]==n)bingo[pl]++;} if(line[pl][0][x]==n)bingo[pl]++; if(line[pl][1][y]==n)bingo[pl]++; if(n==1)bingo[pl]=min(bingo[pl],1); if(bingo[pl]>=tg[pl])stat+=pl+1; //cout<<pl<<" : "<<line[pl][0][x]<<","<<line[pl][1][y]<<","<<naname[pl][0]<<","<<naname[pl][1]<<endl; } //cout<<bingo[0]<<","<<bingo[1]<<endl; if(stat!=0){ break; } } if(stat==2)cout<<"NEKO"<<endl; else if(stat==1)cout<<"USAGI"<<endl; else cout<<"DRAW"<<endl; return 0; }
//////////////////////////////////////// /// tu3 pro-con template /// //////////////////////////////////////// #include <cassert> #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <sstream> #include <algorithm> #include <numeric> #include <functional> #include <vector> #include <queue> #include <string> #include <complex> #include <stack> #include <set> #include <map> #include <list> #include <unordered_map> #include <unordered_set> #include <bitset> #include <regex> using namespace std; //// MACRO //// #define countof(a) (sizeof(a)/sizeof(a[0])) #define REP(i,n) for (int i = 0; i < (n); i++) #define RREP(i,n) for (int i = (n)-1; i >= 0; i--) #define FOR(i,s,n) for (int i = (s); i < (n); i++) #define RFOR(i,s,n) for (int i = (n)-1; i >= (s); i--) #define pos(c,i) c.being() + (i) #define allof(c) c.begin(), c.end() #define aallof(a) a, countof(a) #define partof(c,i,n) c.begin() + (i), c.begin() + (i) + (n) #define apartof(a,i,n) a + (i), a + (i) + (n) #define long long long #define EPS 1e-9 #define INF (1L << 30) #define LINF (1LL << 60) #define PREDICATE(t,a,exp) [&](const t & a) -> bool { return exp; } #define COMPARISON_T(t) bool(*)(const t &, const t &) #define COMPARISON(t,a,b,exp) [&](const t & a, const t & b) -> bool { return exp; } #define CONVERTER(TSrc,t,TDest,exp) [&](const TSrc &t)->TDest { return exp; } inline int sign(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); } inline bool inRange(int val, int min, int max) { return val >= min && val < max; } inline bool inRange(double val, double min, double max) { return val - min > -EPS && val - max < EPS; } template <class T> struct vevector : public vector<vector<T>> { vevector(int n = 0, int m = 0, const T &initial = T()) : vector<vector<T>>(n, vector<T>(m, initial)) { } }; template <class T> struct vevevector : public vector<vevector<T>> { vevevector(int n = 0, int m = 0, int l = 0, const T &initial = T()) : vector<vevector<T>>(n, vevector<T>(m, l, initial)) { } }; template <class T> struct vevevevector : public vector<vevevector<T>> { vevevevector(int n = 0, int m = 0, int l = 0, int k = 0, const T &initial = T()) : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) { } }; //// i/o helper //// #ifdef _DEBUG #define DEBUG WRITE inline void readfrom(string filename) { freopen(filename.c_str(), "r", stdin); } inline void writeto(string filename) { freopen(filename.c_str(), "w", stdout); } #else #define DEBUG(...) inline void readfrom(...) { } inline void writeto(...) { } #endif #ifdef ccout # define cout ccout # define endl cendl #endif struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } }; struct _Writer { bool f; _Writer() : f(false) { } template <class T> _Writer operator ,(const T &rhs) { cout << (f ? " " : "") << rhs; f = true; return *this; } }; #define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__ #define WRITE(...) _Writer(), __VA_ARGS__; cout << endl template <class T> T read() { T t; cin >> t; return t; } template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; } template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; } template <class T> vevector<T> readjag() { return read<T>(read<int>()); } template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(readjag<T>()); return v; } template <class T1, class T2> inline istream & operator >> (istream & in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <class T1, class T2> inline ostream & operator << (ostream &out, pair<T1, T2> &p) { out << p.first << p.second; return out; } template <class T> inline ostream & operator << (ostream &out, const vector<T> &v) { ostringstream ss; for (auto x : v) ss << x << ' '; auto s = ss.str(); out << s.substr(0, s.length() - 1) << endl; return out; } //// start up //// void solve(); int main() { solve(); return 0; } //////////////////// /// template end /// //////////////////// void solve() { int testcases = 1; REP(testcase, testcases) { READ(int, n, u, v, m); vector<int> usa(2 * n + 2, n), neko(2 * n + 2, n); vector<int> usamap(1000001, -1), nekomap(1000001, -1); REP(i, n) REP(j, n) { usamap[read<int>()] = i << 16 | j; } REP(i, n) REP(j, n) { nekomap[read<int>()] = i << 16 | j; } int win = 0; REP(i, m) { READ(int, d); if (!win) { REP(k, 2) { const vector<int> &mp = !k ? usamap : nekomap; vector<int> &te = !k ? usa : neko; int &re = !k ? u : v; int c = 0; if (mp[d] == -1) continue; int i = mp[d] >> 16, j = (short)mp[d]; if (--te[i] == 0) { c++; } // たて if (--te[n + j] == 0) { c++; } // よこ if (i - j == 0) if (--te[2 * n] == 0) { c++; } // ななめ if (i + j + 1 == n) if (--te[2 * n + 1] == 0) { c++; } if (n == 1) { c = min(c, 1); } re -= c; if (re <= 0) { win |= 1 << k; } } } } switch (win) { case 1: WRITE("USAGI"); break; case 2: WRITE("NEKO"); break; default: WRITE("DRAW"); break; } } }
#include <stdio.h> #include <cmath> #include <algorithm> #include <cfloat> #include <stack> #include <queue> #include <vector> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; int diff_row_hidariue[3] = {0,1,1},diff_col_hidariue[3] = {1,0,1}; int diff_row_migiue[2] = {1,1},diff_col_migiue[2] = {-1,0}; int n,u,v,m; struct Info{ int row,col,value; bool exist,checked; }; struct Data{ Data(int arg_row,int arg_col){ row = arg_row; col = arg_col; } int row,col; }; bool rangeCheck(int row,int col){ if(row >= 0 && row <= n-1 && col >= 0 && col <= n-1)return true; else{ return false; } } int main(){ scanf("%d %d %d %d",&n,&u,&v,&m); Info* loc_USAGI = (Info*)malloc(sizeof(Info)*(1000001)); Info* loc_NEKO = (Info*)malloc(sizeof(Info)*(1000001)); for(int i = 1; i <= 1000000; i++){ loc_USAGI[i].exist = false; loc_NEKO[i].exist = false; } Info** map_USAGI = (Info**)malloc(sizeof(Info*)*n); Info** map_NEKO = (Info**)malloc(sizeof(Info*)*n); for(int i = 0; i < n; i++){ map_USAGI[i] = (Info*)malloc(sizeof(Info)*n); map_NEKO[i] = (Info*)malloc(sizeof(Info)*n); } bool** to_Migi_USAGI = new bool*[n]; bool** to_Migi_NEKO = new bool*[n]; bool** to_Shita_USAGI = new bool*[n]; bool** to_Shita_NEKO = new bool*[n]; bool** to_Migishita_USAGI = new bool*[n]; bool** to_Migishita_NEKO = new bool*[n]; bool** to_Hidarishita_USAGI = new bool*[n]; bool** to_Hidarishita_NEKO= new bool*[n]; for(int i = 0; i < n; i++){ to_Migi_USAGI[i] = new bool[n]; to_Migi_NEKO[i] = new bool[n]; to_Shita_USAGI[i] = new bool[n]; to_Shita_NEKO[i] = new bool[n]; to_Migishita_USAGI[i] = new bool[n]; to_Migishita_NEKO[i] = new bool[n]; to_Hidarishita_USAGI[i] = new bool[n]; to_Hidarishita_NEKO[i] = new bool[n]; for(int k = 0; k < n; k++){ to_Migi_USAGI[i][k] = false; to_Migi_NEKO[i][k] = false; to_Shita_USAGI[i][k] = false; to_Shita_NEKO[i][k] = false; to_Migishita_USAGI[i][k] = false; to_Migishita_NEKO[i][k] = false; to_Hidarishita_USAGI[i][k] = false; to_Hidarishita_NEKO[i][k] = false; } } for(int row = 0; row < n; row++){ for(int col = 0; col < n; col++){ map_USAGI[row][col].checked = false; map_NEKO[row][col].checked = false; } } for(int row = 0; row < n; row++){ for(int col = 0; col < n; col++){ scanf("%d",&map_USAGI[row][col].value); loc_USAGI[map_USAGI[row][col].value].exist = true; loc_USAGI[map_USAGI[row][col].value].row = row; loc_USAGI[map_USAGI[row][col].value].col = col; } } for(int row = 0; row < n; row++){ for(int col = 0; col < n; col++){ scanf("%d",&map_NEKO[row][col].value); loc_NEKO[map_NEKO[row][col].value].exist = true; loc_NEKO[map_NEKO[row][col].value].row = row; loc_NEKO[map_NEKO[row][col].value].col = col; } } vector<Data> Usagi_D,Neko_D; int tmp,usagi_line,neko_line,count,start_row,start_col,tmp_row,tmp_col; int usagi_check_num = 0,neko_check_num = 0; bool usagi_FLG,neko_FLG; for(int loop = 0; loop < m; loop++){ scanf("%d",&tmp); usagi_FLG = false; neko_FLG = false; if(loc_USAGI[tmp].exist == true){ usagi_check_num++; usagi_FLG = true; map_USAGI[loc_USAGI[tmp].row][loc_USAGI[tmp].col].checked = true; if(loc_USAGI[tmp].row == 0 || loc_USAGI[tmp].col == 0){ Usagi_D.push_back(Data(loc_USAGI[tmp].row,loc_USAGI[tmp].col)); } } if(loc_NEKO[tmp].exist == true){ neko_check_num++; neko_FLG = true; map_NEKO[loc_NEKO[tmp].row][loc_NEKO[tmp].col].checked = true; if(loc_NEKO[tmp].row == 0 || loc_NEKO[tmp].col == 0){ Neko_D.push_back(Data(loc_NEKO[tmp].row,loc_NEKO[tmp].col)); } } usagi_line = 0; if(usagi_FLG && usagi_check_num >= n){ for(int i = 0; i < Usagi_D.size(); i++){ start_row = Usagi_D[i].row; start_col = Usagi_D[i].col; if(n > 1){ if(start_row == 0 && start_col == 0){ for(int k = 0; k < 3; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; switch(k){ case 0: if(to_Migi_USAGI[start_row][start_col]){ usagi_line++; continue; } break; case 1: if(to_Shita_USAGI[start_row][start_col]){ usagi_line++; continue; } break; case 2: if(to_Migishita_USAGI[start_row][start_col]){ usagi_line++; continue; } break; } while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[k]; tmp_col = tmp_col + diff_col_hidariue[k]; } if(count >= n){ usagi_line++; switch(k){ case 0: to_Migi_USAGI[start_row][start_col] = true; break; case 1: to_Shita_USAGI[start_row][start_col] = true; break; case 2: to_Migishita_USAGI[start_row][start_col] = true; break; } } } }else if(start_row == 0 && start_col == n-1){ for(int k = 0; k < 2; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; if(k == 0){ if(to_Hidarishita_USAGI[start_row][start_col]){ usagi_line++; continue; } }else{ if(to_Shita_USAGI[start_row][start_col]){ usagi_line++; continue; } } while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_migiue[k]; tmp_col = tmp_col + diff_col_migiue[k]; } if(count >= n){ usagi_line++; if(k == 0){ to_Hidarishita_USAGI[start_row][start_col] = true; }else{ to_Shita_USAGI[start_row][start_col] = true; } } } }else if(start_row == 0){ tmp_row = start_row; tmp_col = start_col; count = 0; if(to_Shita_USAGI[start_row][start_col]){ usagi_line++; }else{ while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[1]; tmp_col = tmp_col + diff_col_hidariue[1]; } if(count >= n){ usagi_line++; to_Shita_USAGI[start_row][start_col] = true; } } }else{ //tmp_col == 0 tmp_row = start_row; tmp_col = start_col; count = 0; if(to_Migi_USAGI[start_row][start_col]){ usagi_line++; }else{ while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[0]; tmp_col = tmp_col + diff_col_hidariue[0]; } if(count >= n){ usagi_line++; to_Migi_USAGI[start_row][start_col] = true; } } } }else{ usagi_line = 1; } } } neko_line = 0; if(neko_FLG && neko_check_num >= n){ for(int i = 0; i < Neko_D.size(); i++){ start_row = Neko_D[i].row; start_col = Neko_D[i].col; if(n > 1){ if(start_row == 0 && start_col == 0){ for(int k = 0; k < 3; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; switch(k){ case 0: if(to_Migi_NEKO[start_row][start_col]){ neko_line++; continue; } break; case 1: if(to_Shita_NEKO[start_row][start_col]){ neko_line++; continue; } break; case 2: if(to_Migishita_NEKO[start_row][start_col]){ neko_line++; continue; } break; } while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[k]; tmp_col = tmp_col + diff_col_hidariue[k]; } if(count >= n){ neko_line++; switch(k){ case 0: to_Migi_NEKO[start_row][start_col] = true; break; case 1: to_Shita_NEKO[start_row][start_col] = true; break; case 2: to_Migishita_NEKO[start_row][start_col] = true; break; } } } }else if(start_row == 0 && start_col == n-1){ for(int k = 0; k < 2; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; if(k == 0){ if(to_Hidarishita_NEKO[start_row][start_col]){ neko_line++; continue; } }else{ if(to_Shita_NEKO[start_row][start_col]){ neko_line++; continue; } } while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_migiue[k]; tmp_col = tmp_col + diff_col_migiue[k]; } if(count >= n){ neko_line++; if(k == 0){ to_Hidarishita_NEKO[start_row][start_col] = true; }else{ to_Shita_NEKO[start_row][start_col] = true; } } } }else if(start_row == 0){ tmp_row = start_row; tmp_col = start_col; count = 0; if(to_Shita_NEKO[start_row][start_col]){ neko_line++; }else{ while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[1]; tmp_col = tmp_col + diff_col_hidariue[1]; } if(count >= n){ neko_line++; to_Shita_NEKO[start_row][start_col] = true; } } }else{ //tmp_col == 0 tmp_row = start_row; tmp_col = start_col; count = 0; if(to_Migi_NEKO[start_row][start_col]){ neko_line++; }else{ while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[0]; tmp_col = tmp_col + diff_col_hidariue[0]; } if(count >= n){ neko_line++; to_Migi_NEKO[start_row][start_col] = true; } } } }else{ neko_line = 1; } } } if(usagi_line >= u && neko_line >= v){ printf("DRAW\n"); return 0; }else if(usagi_line >= u && neko_line < v){ printf("USAGI\n"); return 0; }else if(usagi_line < u && neko_line >= v){ printf("NEKO\n"); return 0; } } printf("DRAW\n"); return 0; }
#include <bits/stdc++.h> using namespace std; struct cod { int x, y; }; long long n, u, v, m; string res[3] = {"USAGI", "NEKO", "DRAW"}; vector<long long> mv; map<long long, cod> mp[2]; map<long long, long long> row[2], col[2], sum[2], diff[2]; int solve(); int main() { cin >> n >> u >> v >> m; for(int t = 0; t < 2; ++t) for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) { int x; cin >> x; mp[t][x] = {i, j}; } mv.resize(m); for(int i = 0; i < m; ++i) cin >> mv[i]; cout << res[solve()] << endl; return 0; } int solve() { long long cnt[2] = {0}; for(int i = 0; i < m; ++i) { for(int t = 0; t < 2; ++t) if(mp[t].find(mv[i]) != mp[t].end()) { cod now = mp[t][mv[i]]; if(++row[t][now.x] == n) ++cnt[t]; if(++col[t][now.y] == n) ++cnt[t]; if(++sum[t][now.x + now.y] == n) ++cnt[t]; if(++diff[t][now.x - now.y] == n) ++cnt[t]; if(n == 1) cnt[t] = min(cnt[t], 1LL); } if(cnt[0] >= u && cnt[1] >= v) return 2; if(cnt[0] >= u) return 0; if(cnt[1] >= v) return 1; } return 2; }
#include <vector> #include <list> #include <map> #include <set> #include <stack> #include <queue> #include <deque> #include <algorithm> #include <utility> #include <functional> #include <sstream> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <climits> #include <cassert> using namespace std; 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 EXIST(s,e) ((s).find(e)!=(s).end()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) const int INF = INT_MAX/10; int main() { int n, u, v, m; cin >> n >> u >> v >> m; vvi ufield(n, vi(n)); map<int, vector<pii> > utable; REP(i, n) { REP(j, n) { cin >> ufield[i][j]; utable[ufield[i][j]].push_back(make_pair(i, j)); } } vvi nfield(n, vi(n)); map<int, vector<pii> > ntable; REP(i, n) { REP(j, n) { cin >> nfield[i][j]; ntable[nfield[i][j]].push_back(make_pair(i, j)); } } vvi usagi(n, vi(n, INF)); vvi neko(n, vi(n, INF)); int num; FOR(i, 1, m+1) { cin >> num; REP(j, utable[num].size()) { usagi[utable[num][j].first][utable[num][j].second] = i; } REP(j, ntable[num].size()) { neko[ntable[num][j].first][ntable[num][j].second] = i; } } vi ut, nt; REP(i, n) { int um = 0, nm = 0; REP(j, n) { um = max(um, usagi[i][j]); nm = max(nm, neko[i][j]); } ut.push_back(um); nt.push_back(nm); } REP(i, n) { int um = 0, nm = 0; REP(j, n) { um = max(um, usagi[j][i]); nm = max(nm, neko[j][i]); } ut.push_back(um); nt.push_back(nm); } int um = 0, nm = 0; REP(i, n) { um = max(um, usagi[i][i]); nm = max(nm, neko[i][i]); } ut.push_back(um); nt.push_back(nm); um = 0, nm = 0; REP(i, n) { um = max(um, usagi[i][n-i-1]); nm = max(nm, neko[i][n-i-1]); } ut.push_back(um); nt.push_back(nm); sort(ALL(ut)); sort(ALL(nt)); if(n==1){ FOR(i,1,ut.size()){ ut[i]=INF; nt[i]=INF; } } FOR(i, ut.size(), 13) { ut.push_back(INF); nt.push_back(INF); } //if(u-1 >= ut.size()) { // if(v-1 >= nt.size()) { // cout << "DRAW" << endl; // return 0; // } else { // if(nt[v-1] != INF) { // cout << "NEKO" << endl; // return 0; // } // } //} //if(v-1 >= ut.size()) { // if(u-1 >= nt.size()) { // assert(0); // } else { // if(ut[u-1] != INF) { // cout << "USAGI" << endl; // return 0; // } // } //} if(ut[u-1] < nt[v-1]) { cout << "USAGI" << endl; } else if(ut[u-1] > nt[v-1]) { cout << "NEKO" << endl; } else { cout << "DRAW" << endl; } }
#include <iostream> #include <vector> #include <map> using namespace std; int main() { int n, win_cnt[2] = {}, m; cin >> n >> win_cnt[0] >> win_cnt[1] >> m; if(n == 1) { for(int i=0; i<2; ++i) { win_cnt[i] *= 4; } } vector<vector<int>> cntx(2, vector<int>(n)), cnty(2, vector<int>(n)); vector<int> cntd(2), cntd2(2); vector<vector<vector<int>>> vv(2, vector<vector<int>>(n, vector<int>(n))); vector<map<int, pair<int, int>>> ma(2); for(int k=0; k<2; ++k) { for(int i=0; i<n; ++i) { for(int j=0; j<n; ++j) { cin >> vv[k][i][j]; ma[k][vv[k][i][j]] = make_pair(i, j); } } } vector<int> M(m); for(int i=0; i<m; ++i) { cin >> M[i]; } string win = "DRAW"; int cnt[2] = {}; for(int i=0; i<m; ++i) { bool finish = false; for(int k=0; k<2; ++k) { if(ma[k].count(M[i]) != 1) { continue; } pair<int, int> p = ma[k][M[i]]; int y = p.first, x = p.second; cntx[k][x]++; cnty[k][y]++; if(y == x) { cntd[k]++; if(cntd[k] == n) { cnt[k]++; } } if(y + x == n-1) { cntd2[k]++; if(cntd2[k] == n) { cnt[k]++; } } if(cntx[k][x] == n) { cnt[k]++; } if(cnty[k][y] == n) { cnt[k]++; } if(cnt[k] >= win_cnt[k]) { finish = true; if(k == 1 && win != "DRAW") { win = "DRAW"; } else if(k == 0) { win = "USAGI"; } else { win = "NEKO"; } } } if(finish) { break; } } cout << win << endl; }
#include<iostream> #include<map> #include<vector> using namespace std; typedef pair<int, int> pii; int calc(vector<vector<bool> > &mat){ int res = 0; int n = mat.size(); if(n == 1){ return mat[0][0]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if(mat[i][j] == false)break; if(j == n - 1)res++; } for (int j = 0; j < n; j++) { if(mat[j][i] == false)break; if(j == n - 1)res++; } } for (int i = 0; i < n; i++) { if(mat[i][i] == false)break; if(i == n - 1)res++; } for (int i = 0; i < n; i++) { if(mat[i][n - 1 - i] == false)break; if(i == n - 1)res++; } return res; } int main(){ int n, u, v, m; std::cin >> n >> u >> v >> m; map<int, pii> nhash, uhash; vector<vector<bool> > um(n, vector<bool>(n, false)); vector<vector<bool> > nm = um; vector<vector<int> > umat(n, vector<int>(n)); vector<vector<int> > nmat = umat; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { std::cin >> umat[i][j]; uhash[umat[i][j]] = pii(i, j); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { std::cin >> nmat[i][j]; nhash[nmat[i][j]] = pii(i, j); } } for (int i = 0; i < m; i++) { int num; std::cin >> num; if(uhash.find(num) != uhash.end()){ pii pos = uhash[num]; um[pos.first][pos.second] = true; } if(nhash.find(num) != nhash.end()){ pii pos = nhash[num]; nm[pos.first][pos.second] = true; } // std::cout << num << std::endl; // std::cout << "um:" << calc(um) << std::endl; // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // std::cout << um[i][j]; // } // std::cout << std::endl; // } // std::cout << "nm:" << calc(nm) << std::endl; // for (int i = 0; i < n; i++) { // for (int j = 0; j < n; j++) { // std::cout << nm[i][j]; // } // std::cout << std::endl; // } // std::cout << std::endl; if(calc(um) >= u and calc(nm) >= v){ std::cout << "DRAW" << std::endl; return 0; }else if(calc(um) >= u){ std::cout << "USAGI" << std::endl; return 0; }else if(calc(nm) >= v){ std::cout << "NEKO" << std::endl; return 0; } } std::cout << "DRAW" << std::endl; return 0; }
#include<cstdio> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int n,u,v,m,tmp; int c[1000001]; int usa[1000001][2],neko[1000001][2]; int row[2][500],col[2][500],dia[2][2]; int U,V; int main(){ scanf("%d%d%d%d",&n,&u,&v,&m); rep(i,1000001)rep(j,2)usa[i][j] = neko[i][j] = -1; rep(i,n)rep(j,n){ scanf("%d",&tmp); usa[tmp][0] = i; usa[tmp][1] = j; } rep(i,n)rep(j,n){ scanf("%d",&tmp); neko[tmp][0] = i; neko[tmp][1] = j; } rep(i,2){ rep(j,n)row[i][j] = col[i][j] = 0; dia[i][0] = dia[i][1] = 0; } U = V = 0; if(n==1){ u*=4; v*=4; } rep(i,m)scanf("%d",&c[i]); bool f = false; rep(i,m){ if(usa[c[i]][0]>=0){ int y = usa[c[i]][0], x = usa[c[i]][1]; row[0][y]++; if(row[0][y]==n)U++; col[0][x]++; if(col[0][x]==n)U++; if(x == y){ dia[0][0]++; if(dia[0][0]==n)U++; } if(x+y == n-1){ dia[0][1]++; if(dia[0][1]==n)U++; } } if(neko[c[i]][0]>=0){ int y = neko[c[i]][0], x = neko[c[i]][1]; row[1][y]++; if(row[1][y]==n)V++; col[1][x]++; if(col[1][x]==n)V++; if(x == y){ dia[1][0]++; if(dia[1][0]==n)V++; } if(x + y == n-1){ dia[1][1]++; if(dia[1][1]==n)V++; } } if(U>=u && V>=v){ break; }else if(U>=u){ printf("USAGI\n"); f = true; break; }else if(V>=v){ printf("NEKO\n"); f = true; break; } } if(!f)printf("DRAW\n"); }
#include <bits/stdc++.h> #define ALL(a) (a).begin(), (a).end() #define llong long long using namespace std; using ARRAY = vector<int>; using cont = vector<ARRAY>; struct T{ ARRAY row, column, naname; map<int, pair<size_t, size_t>> idx; size_t acc = 0; size_t n; T(size_t n_, cont m):n(n_), row(n_), column(n_), naname(2){ for(size_t i = 0; i < n_; i++)for(size_t j = 0; j < n_; j++){ idx[m[i][j]] = {i,j}; } } void ume(int e){ if(idx.find(e) == idx.end())return; auto i = idx[e].first; auto j = idx[e].second; row[i]++; column[j]++; if(i == j)naname[0]++; if(i == n-1-j)naname[1]++; if(row[i] == n){ acc++; row[i]+= n; } if(column[j] == n){ acc++; column[j] += n; } if(naname[0] == n){ acc++; naname[0] += n; } if(naname[1] == n){ acc++; naname[1] += n; } } void print(){ // for(auto e : row)cerr << e << " "; // for(auto e : column)cerr << e << " "; // cerr << naname[0] << " "; // cerr << naname[1] << endl; } }; void calc(int u, int v, int ub, int nb, ARRAY &m){ int uacc = 0, nacc = 0; for(auto e : m){ if(e == ub){ uacc++; ub *= -1; } if(e == nb){ nacc++; nb *= -1; } if(ub >= u || nb >= v)break; } // cerr << "C" << u << " " << v << endl; // cerr << uacc << " " << nacc << endl; if(uacc >= u && nacc >= v){ cout << "DRAW" << endl; } else if(uacc >= u){ cout << "USAGI" << endl; } else if(nacc >= v){ cout << "NEKO" << endl; } else{ cout << "DRAW" << endl; } } signed main(){ int n, u, v, M; cin >> n >> u >> v >> M; cont udata(n,ARRAY(n)); cont ndata(n,ARRAY(n)); for(auto &&a : udata)for(auto &&e : a)cin >> e; for(auto &&a : ndata)for(auto &&e : a)cin >> e; ARRAY m(M); for(auto &&e : m)cin >> e; if(n == 1){ calc(u,v,udata[0][0],ndata[0][0],m); return 0; } T usagi(n,udata), neko(n,ndata); set<int> used; for(auto e : m){ if(used.find(e) != used.end())continue; usagi.ume(e); neko.ume(e); used.insert(e); if(usagi.acc >= u || neko.acc >= v)break; } // usagi.print(); // neko.print(); if(usagi.acc >= u && neko.acc >= v){ cout << "DRAW" << endl; } else if(usagi.acc >= u){ cout << "USAGI" << endl; } else if(neko.acc >= v){ cout << "NEKO" << endl; } else{ cout << "DRAW" << endl; } return 0; } /* signed main(){ int n, u, v, M; cin >> n >> u >> v >> M; cont usagi(n,ARRAY(n)); cont neko(n,ARRAY(n)); for(auto &&a : usagi)for(auto &&e : a)cin >> e; for(auto &&a : neko)for(auto &&e : a)cin >> e; ARRAY m(M); for(auto &&e : m)cin >> e; map<int, pair<int,int>> uidx, nidx; for(size_t i = 0; i < n; i++)for(size_t j = 0; j < n; j++){ uidx[usagi[i][j]] = {i,j}; nidx[neko[i][j]] = {i,j}; } ARRAY ub(2*n+2); ARRAY nb(2*n+2); // for(auto e : uidx)cerr << e.second.first << "," << e.second.second << " ";cerr << endl; int uacc = 0, nacc = 0; for(auto e : m){ // cerr << e << endl; if(uidx.find(e) != uidx.end()){ auto ut = uidx[e]; // cerr << "u " << ut.first << " ," << ut.second << endl; ub[ut.first]++; ub[n+ut.second]++; if(ub[ut.first] == n){ uacc++; ub[ut.first] = -(int)1e9; } if(ub[n+ut.second] == n){ uacc++; ub[n+ut.second] = -(int)1e9; } if(ut.first == ut.second){ ub[2*n]++; if(ub[2*n] == n){ uacc++; ub[2*n] = -(int)1e9; } } if(ut.first == n-ut.second-1){ ub[2*n+1]++; if(ub[2*n+1] == n){ uacc++; ub[2*n+1] = -(int)1e9; } } } if(nidx.find(e) != nidx.end()){ auto nt = nidx[e]; // cerr << "n " << nt.first << " ," << nt.second << endl; nb[nt.first]++; nb[n+nt.second]++; if(nb[nt.first] == n){ nacc++; nb[nt.first] = -(int)1e9; } if(nb[n+nt.second] == n){ nacc++; nb[n+nt.second] = -(int)1e9; } if(nt.first == nt.second){ nb[2*n]++; if(nb[2*n] == n){ nacc++; nb[2*n] = -(int)1e9; } } if(nt.first == n-nt.second-1){ nb[2*n+1]++; if(nb[2*n+1] == n){ nacc++; nb[2*n+1] = -(int)1e9; } } } if(e == 1){ // for(auto e : ub)cerr <<e << " "; cerr << endl; // for(auto e : nb)cerr <<e << " "; cerr << endl; // cerr << endl; } if(uacc >= u || nacc >= v)break; } // for(auto e : ub)cerr <<e << " "; cerr << endl; // for(auto e : nb)cerr <<e << " "; cerr << endl; // cerr << uacc << " " << nacc << endl; if(uacc >= u && nacc >= v){ cout << "DRAW" << endl; } else if(uacc >= u){ cout << "USAGI" << endl; } else if(nacc >= u){ cout << "NEKO" << endl; } else{ cout << "DRAW" << endl; } return 0; } */
#include<bits/stdc++.h> #define range(i,a,b) for(int i = (a); i < (b); i++) #define rep(i,b) for(int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; using namespace std; const int gmax_n = 505; int cntX[2][gmax_n] = {0}; int cntY[2][gmax_n] = {0}; bool usa[gmax_n][gmax_n] = {{0}}, neko[gmax_n][gmax_n] = {{0}}; int checkPointU(int n, int u, pair<int, int> p){ int y = p.first; int x = p.second; usa[y][x] = 1; int cnt = 0; cntX[0][x]++; cntY[0][y]++; rep(i,n){ if(cntX[0][i] == n) cnt++; if(cntY[0][i] == n) cnt++; } bool f = true; rep(i,n) if(usa[i][i] == 0) f = false; if(f) cnt++; f = true; rep(i,n) if(usa[i][n - 1 - i] == 0) f = false; if(f) cnt++; //y = find(y,parY[0][x], cntY[0][x]); //x = find(x,parX[0][y], cntX[0][y]); //show(cntX[0][y][x]) //show(cntY[0][x][y]) //show(cnt) if(n == 1) cnt = 1; if(cnt >= u || cnt >= u) return 1; else return 0; } int checkPointN(int n, int v, pair<int, int> p){ int y = p.first; int x = p.second; neko[y][x] = 1; int cnt = 0; cntX[1][x]++; cntY[1][y]++; rep(i,n){ if(cntX[1][i] == n) cnt++; if(cntY[1][i] == n) cnt++; } bool f = true; rep(i,n) if(neko[i][i] == 0) f = false; if(f) cnt++; f = true; rep(i,n) if(neko[i][n - 1 - i] == 0) f = false; if(f) cnt++; //y = find(y,parY[0][x], cntY[0][x]); //x = find(x,parX[0][y], cntX[0][y]); //show(cntX[0][y][x]) //show(cntY[0][x][y]) if(n == 1) cnt = 1; if(cnt >= v || cnt >= v) return 1; else return 0; } int main(){ int n, u, v, m; cin >> n >> u >> v >> m; int x; map<int,pair<int, int>> up, np; rep(i,n){ rep(j,n){ cin >> x; up[x] = make_pair(i,j); } } rep(i,n){ rep(j,n){ cin >> x; np[x] = make_pair(i,j); } } int ans = 0; rep(i,m){ int a; cin >> a; //cout << a << endl; if(ans == 0){ int utmp = -1, vtmp = -1; utmp = (up.count(a) ? checkPointU(n,u,up[a]) : 0); vtmp = (np.count(a) ? checkPointN(n,v,np[a]) : 0); // show(utmp) //show(vtmp) if(utmp == 0 && vtmp != 0) ans = 1; else if(utmp != 0 && vtmp == 0) ans = 2; else if(utmp != 0 && vtmp != 0) ans = 3; else if(utmp == 0 && vtmp == 0); else assert(0); } // show(ans) // rep(i,n){ rep(j,n){ cout << usa[i][j]; } cout << endl; } // cout << endl; // rep(i,n){ rep(j,n){ cout << neko[i][j]; } cout << endl; } } if(ans == 1) cout << "NEKO" << endl; else if(ans == 2) cout << "USAGI" << endl; else cout << "DRAW" << endl; }
#include <stdio.h> #include <cmath> #include <algorithm> #include <cfloat> #include <stack> #include <queue> #include <vector> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; int diff_row_hidariue[3] = {0,1,1},diff_col_hidariue[3] = {1,0,1}; int diff_row_migiue[2] = {1,1},diff_col_migiue[2] = {-1,0}; int n,u,v,m; struct Info{ int row,col,value; bool exist,checked; }; struct Data{ Data(int arg_row,int arg_col){ row = arg_row; col = arg_col; } int row,col; }; bool rangeCheck(int row,int col){ if(row >= 0 && row <= n-1 && col >= 0 && col <= n-1)return true; else{ return false; } } int main(){ scanf("%d %d %d %d",&n,&u,&v,&m); Info* loc_USAGI = (Info*)malloc(sizeof(Info)*(1000001)); Info* loc_NEKO = (Info*)malloc(sizeof(Info)*(1000001)); for(int i = 1; i <= 1000000; i++){ loc_USAGI[i].exist = false; loc_NEKO[i].exist = false; } Info** map_USAGI = (Info**)malloc(sizeof(Info*)*n); Info** map_NEKO = (Info**)malloc(sizeof(Info*)*n); for(int i = 0; i < n; i++){ map_USAGI[i] = (Info*)malloc(sizeof(Info)*n); map_NEKO[i] = (Info*)malloc(sizeof(Info)*n); } for(int row = 0; row < n; row++){ for(int col = 0; col < n; col++){ map_USAGI[row][col].checked = false; map_NEKO[row][col].checked = false; } } for(int row = 0; row < n; row++){ for(int col = 0; col < n; col++){ scanf("%d",&map_USAGI[row][col].value); loc_USAGI[map_USAGI[row][col].value].exist = true; loc_USAGI[map_USAGI[row][col].value].row = row; loc_USAGI[map_USAGI[row][col].value].col = col; } } for(int row = 0; row < n; row++){ for(int col = 0; col < n; col++){ scanf("%d",&map_NEKO[row][col].value); loc_NEKO[map_NEKO[row][col].value].exist = true; loc_NEKO[map_NEKO[row][col].value].row = row; loc_NEKO[map_NEKO[row][col].value].col = col; } } vector<Data> Usagi_D,Neko_D; int tmp,usagi_line,neko_line,count,start_row,start_col,tmp_row,tmp_col; int usagi_check_num = 0,neko_check_num = 0; bool usagi_FLG,neko_FLG; for(int loop = 0; loop < m; loop++){ scanf("%d",&tmp); usagi_FLG = false; neko_FLG = false; if(loc_USAGI[tmp].exist == true){ usagi_check_num++; usagi_FLG = true; map_USAGI[loc_USAGI[tmp].row][loc_USAGI[tmp].col].checked = true; if(loc_USAGI[tmp].row == 0 || loc_USAGI[tmp].col == 0){ Usagi_D.push_back(Data(loc_USAGI[tmp].row,loc_USAGI[tmp].col)); } } if(loc_NEKO[tmp].exist == true){ neko_check_num++; neko_FLG = true; map_NEKO[loc_NEKO[tmp].row][loc_NEKO[tmp].col].checked = true; if(loc_NEKO[tmp].row == 0 || loc_NEKO[tmp].col == 0){ Neko_D.push_back(Data(loc_NEKO[tmp].row,loc_NEKO[tmp].col)); } } usagi_line = 0; if(usagi_FLG && usagi_check_num >= n){ for(int i = 0; i < Usagi_D.size(); i++){ start_row = Usagi_D[i].row; start_col = Usagi_D[i].col; if(n > 1){ if(start_row == 0 && start_col == 0){ for(int k = 0; k < 3; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[k]; tmp_col = tmp_col + diff_col_hidariue[k]; } if(count >= n){ usagi_line++; } } }else if(start_row == 0 && start_col == n-1){ for(int k = 0; k < 2; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_migiue[k]; tmp_col = tmp_col + diff_col_migiue[k]; } if(count >= n){ usagi_line++; } } }else if(start_row == 0){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[1]; tmp_col = tmp_col + diff_col_hidariue[1]; } if(count >= n){ usagi_line++; } }else{ //tmp_col == 0 tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[0]; tmp_col = tmp_col + diff_col_hidariue[0]; } if(count >= n){ usagi_line++; } } }else{ usagi_line = 1; } } } neko_line = 0; if(neko_FLG && neko_check_num >= n){ for(int i = 0; i < Neko_D.size(); i++){ start_row = Neko_D[i].row; start_col = Neko_D[i].col; if(n > 1){ if(start_row == 0 && start_col == 0){ for(int k = 0; k < 3; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[k]; tmp_col = tmp_col + diff_col_hidariue[k]; } if(count >= n){ neko_line++; } } }else if(start_row == 0 && start_col == n-1){ for(int k = 0; k < 2; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_migiue[k]; tmp_col = tmp_col + diff_col_migiue[k]; } if(count >= n){ neko_line++; } } }else if(start_row == 0){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[1]; tmp_col = tmp_col + diff_col_hidariue[1]; } if(count >= n){ neko_line++; } }else{ //tmp_col == 0 tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[0]; tmp_col = tmp_col + diff_col_hidariue[0]; } if(count >= n){ neko_line++; } } }else{ neko_line = 1; } } } if(usagi_line >= u && neko_line >= v){ printf("DRAW\n"); return 0; }else if(usagi_line >= u && neko_line < v){ printf("USAGI\n"); return 0; }else if(usagi_line < u && neko_line >= v){ printf("NEKO\n"); return 0; } } printf("DRAW\n"); return 0; }
#include<iostream> #include<sstream> #include<algorithm> #include<set> #include<map> #include<queue> #include<complex> #include<cstdio> #include<cstdlib> #include<cstring> #include<cassert> #define rep(i,n) for(int i=0;i<(int)n;i++) #define all(c) (c).begin(),(c).end() #define mp make_pair #define pb push_back #define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++) #define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pi; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; int n, u, v, m; int a[500][500], b[500][500], pa[1000001], pb[1000001]; int ra[500], ca[500], da[2], rb[500], cb[500], db[2]; int ck(int num, int a[500][500], int *p, int *r, int *c, int *d){ if(p[num] < 0) return 0; int y = p[num] / n, x = p[num] % n, res = 0; if(a[y][x] < 0) return 0; if(n == 1) return 1; a[y][x] = -1; if(y == x) if(++d[0] == n) res++; if(y == n - x - 1) if(++d[1] == n) res++; if(++r[y] == n) res++; if(++c[x] == n) res++; return res; } int main(){ scanf("%d%d%d%d", &n, &u, &v, &m); memset(pa, -1, sizeof(pa)); memset(pb, -1, sizeof(pb)); rep(i, n) rep(j, n) scanf("%d", a[i] + j), pa[a[i][j]] = i * n + j; rep(i, n) rep(j, n) scanf("%d", b[i] + j), pb[b[i][j]] = i * n + j; int aa = 0, bb = 0; rep(i, m){ int t; scanf("%d", &t); aa += ck(t, a, pa, ra, ca, da); bb += ck(t, b, pb, rb, cb, db); if(aa >= u && bb < v){ cout << "USAGI" << endl; return 0; } if(aa < u && bb >= v){ cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; int main(){ int n,u,v,m; cin>>n>>u>>v>>m; vector<int> ax(n),ay(n),bx(n),by(n); int as=0,al=0,ar=0,bl=0,br=0,bs=0; map<int,pair<int,int>> a,b; rep(i,n)rep(j,n){ int x;cin>>x; a[x]={i,j}; } rep(i,n)rep(j,n){ int x;cin>>x; b[x]={i,j}; } set<int> st; rep(i,m){ int x;cin>>x; if(st.count(x))continue; st.insert(x); if(a.count(x)){ auto p = a[x]; if(++ax[p.first]==n)++as; if(n>=2){ if(++ay[p.second]==n)++as; if(p.first==p.second&&++al==n)++as; if(p.first+p.second==n-1&&++ar==n)++as; } } if(b.count(x)){ auto p = b[x]; if(++bx[p.first]==n)++bs; if(n>=2){ if(++by[p.second]==n)++bs; if(p.first==p.second&&++bl==n)++bs; if(p.first+p.second==n-1&&++br==n)++bs; } } if(as>=u&&bs>=v){ cout<<"DRAW"<<endl; return 0; } if(as>=u){ cout<<"USAGI"<<endl; return 0; } if(bs>=v){ cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; #define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i) #define rep(i,n) REP(i, 0, n) typedef long long int i64; typedef pair<int, int> pint; map<int, pint> usam, nekom; int usum[2][501], nsum[2][501]; int m[100000]; int main() { int N, U, V, M; scanf("%d%d%d%d", &N, &U, &V, &M); int num; rep(i, N) rep(j, N) { scanf("%d", &num); usam[num] = pint(j, i); } rep(i, N) rep(j, N) { scanf("%d", &num); nekom[num] = pint(j, i); } rep(i, M) scanf("%d", m + i); rep(i, M) { if(usam.count(m[i])) { usum[0][usam[m[i]].first]++; usum[1][usam[m[i]].second]++; if(usam[m[i]].first == usam[m[i]].second) usum[0][N]++; if(usam[m[i]].first == N - 1 - usam[m[i]].second) usum[1][N]++; } if(nekom.count(m[i])) { nsum[0][nekom[m[i]].first]++; nsum[1][nekom[m[i]].second]++; if(nekom[m[i]].first == nekom[m[i]].second) nsum[0][N]++; if(nekom[m[i]].first == N - 1 - nekom[m[i]].second) nsum[1][N]++; } int un = 0, vn = 0; rep(i, 2) rep(j, N + 1) if(usum[i][j] == N) un++; rep(i, 2) rep(j, N + 1) if(nsum[i][j] == N) vn++; if(N == 1) un = min(un, 1), vn = min(vn, 1); if(un >= U && vn >= V) break; else if(un >= U) goto USA; else if(vn >= V) goto NEKO; } puts("DRAW"); return 0;; USA: puts("USAGI"); return 0; NEKO: puts("NEKO"); return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <climits> #include <iostream> #include <vector> #include <string> #include <sstream> #include <algorithm> #include <utility> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <functional> using namespace std; #define fst first #define scd second #define PB push_back #define MP make_pair #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define omajinai ios::sync_with_stdio(false);cin.tie(0) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;} template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;} template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<typename T>T get(){T a;cin>>a;return a;} template<typename T>T rev(T a){reverse(all(a));return a;} template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;} const int inf = 1e9; const ll linf = 3e18; const double eps = 1e-9; int n, u, v, m; pii usacard[1000001], nekocard[1000001]; int usarow[501], usacol[501], usaul, usaur; int nekorow[501], nekocol[501], nekoul, nekour; signed main() { scanf("%d%d%d%d", &n, &u, &v, &m); fill_n(usacard, 1000001, pii(-1, 0)); fill_n(nekocard, 1000001, pii(-1, 0)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int a; scanf("%d", &a); usacard[a] = pii(i, j); } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int a; scanf("%d", &a); nekocard[a] = pii(i, j); } } int usa = 0, neko = 0; for (int i = 0; i < m; ++i) { int num; scanf("%d", &num); pii p; { p = usacard[num]; if (p.fst == -1) goto pos1; if (n == 1) { usa++; goto pos1; } usarow[p.fst]++; usa += usarow[p.fst] == n; usacol[p.scd]++; usa += usacol[p.scd] == n; if (p.fst == p.scd) { usaul++; usa += usaul == n; } if (p.fst == n - p.scd - 1) { usaur++; usa += usaur == n; } pos1:; } { p = nekocard[num]; if (p.fst == -1) goto pos2; if (n == 1) { neko++; goto pos2; } nekorow[p.fst]++; neko += nekorow[p.fst] == n; nekocol[p.scd]++; neko += nekocol[p.scd] == n; if (p.fst == p.scd) { nekoul++; neko += nekoul == n; } if (p.fst == n - p.scd - 1) { nekour++; neko += nekour == n; } pos2:; } if (usa >= u && neko >= v) { puts("DRAW"); return 0; } if (usa >= u) { puts("USAGI"); return 0; } if (neko >= v) { puts("NEKO"); return 0; } } 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 <functional> using namespace std; #define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++) #define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++) #define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--) #define int long long int template<typename T> void chmax(T &a, T b) {a = max(a, b);} template<typename T> void chmin(T &a, T b) {a = min(a, b);} template<typename T> void chadd(T &a, T b) {a = a + b;} typedef pair<int, int> pii; typedef long long ll; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; constexpr ll INF = 1001001001001001LL; constexpr ll MOD = 1000000007LL; int N, U, V, M; int rab[1000010], cat[1000010]; int cat_row[510], cat_column[510], cat_diag[2]; int rab_row[510], rab_column[510], rab_diag[2]; signed main() { cin >> N >> U >> V >> M; memset(rab, -1, sizeof(rab)); memset(cat, -1, sizeof(cat)); rep(i,0,N) rep(j,0,N) { int num; cin >> num; rab[num] = i*N + j; } rep(i,0,N) rep(j,0,N) { int num; cin >> num; cat[num] = i*N + j; } int rab_cnt = 0, cat_cnt = 0; rep(i,0,M) { int num; cin >> num; if(~rab[num]) { int rx = rab[num] / N, ry = rab[num] % N; if(++rab_row[rx] == N) rab_cnt++; if(++rab_column[ry] == N) rab_cnt++; if(rx == ry && ++rab_diag[0] == N) rab_cnt++; if(rx + ry == N-1 && ++rab_diag[1] == N) rab_cnt++; } if(~cat[num]) { int cx = cat[num] / N, cy = cat[num] % N; if(++cat_row[cx] == N) cat_cnt++; if(++cat_column[cy] == N) cat_cnt++; if(cx == cy && ++cat_diag[0] == N) cat_cnt++; if(cx + cy == N-1 && ++cat_diag[1] == N) cat_cnt++; } if(N == 1) chmin(rab_cnt, 1LL), chmin(cat_cnt, 1LL); if(rab_cnt >= U && cat_cnt >= V) { cout << "DRAW" << endl; return 0; } if(rab_cnt >= U) { cout << "USAGI" << endl; return 0; } if(cat_cnt >= V) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, u, v, m; static int rab[512][512], cat[512][512]; static int doner[512][512], donec[512][512]; static pair<int, int> rabpos[1000001], catpos[1000001]; scanf("%d %d %d %d", &n, &u, &v, &m); for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ scanf("%d", &rab[i][j]); rabpos[rab[i][j]] = make_pair(i, j); } } for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ scanf("%d", &cat[i][j]); catpos[cat[i][j]] = make_pair(i, j); } } for (int i = 1; i <= m; i++){ int x; scanf("%d", &x); pair<int, int> r = rabpos[x]; doner[r.first][r.second] = i; r = catpos[x]; donec[r.first][r.second] = i; } vector<int> rabmin, catmin; for (int i = 0; i < 13; i++){ rabmin.push_back(1000000000); catmin.push_back(1000000000); } for (int i = 1; i <= n; i++){ int rabmax = 0, catmax = 0; bool rabok = 1, catok = 1; for (int j = 1; j <= n; j++){ rabmax = max(rabmax, doner[i][j]); catmax = max(catmax, donec[i][j]); rabok &= (!!doner[i][j]); catok &= (!!donec[i][j]); } if (rabok) rabmin.push_back(rabmax); if (catok) catmin.push_back(catmax); if (n != 1){ rabmax = 0, catmax = 0; rabok = 1, catok = 1; for (int j = 1; j <= n; j++){ rabmax = max(rabmax, doner[j][i]); catmax = max(catmax, donec[j][i]); rabok &= (!!doner[j][i]); catok &= (!!donec[j][i]); } if (rabok) rabmin.push_back(rabmax); if (catok) catmin.push_back(catmax); } } if (n != 1){ int rabmax = 0, catmax = 0; bool rabok = 1, catok = 1; for (int i = 1; i <= n; i++){ rabmax = max(rabmax, doner[i][i]); catmax = max(catmax, donec[i][i]); rabok &= (!!doner[i][i]); catok &= (!!donec[i][i]); } if (rabok) rabmin.push_back(rabmax); if (catok) catmin.push_back(catmax); rabmax = 0, catmax = 0; rabok = 1, catok = 1; for (int i = 1; i <= n; i++){ rabmax = max(rabmax, doner[i][n - i + 1]); catmax = max(catmax, donec[i][n - i + 1]); rabok &= (!!doner[i][n - i + 1]); catok &= (!!donec[i][n - i + 1]); } if (rabok) rabmin.push_back(rabmax); if (catok) catmin.push_back(catmax); } sort(rabmin.begin(), rabmin.end()); sort(catmin.begin(), catmin.end()); --u; --v; if (rabmin[u] == catmin[v] || min(rabmin[u], catmin[v]) > m){ return (!printf("DRAW\n")); } printf("%s\n", rabmin[u] < catmin[v] ? "USAGI" : "NEKO"); return (0); }
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<vector> #include<queue> #include<map> #include<set> using namespace std; int utate[520]; int uyoko[520]; int unaname[5]; int ntate[520]; int nyoko[520]; int nnaname[5]; int ufsuuji[1200000]; int ussuuji[1200000]; int nfsuuji[1200000]; int nssuuji[1200000]; int n,u,v,m; int k; int nkotae,ukotae; int main(){ cin >> n >> u >> v >> m; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin >> k; ufsuuji[k]=i; ussuuji[k]=j; } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin >> k; nfsuuji[k]=i; nssuuji[k]=j; } } for(int i=0;i<m;i++){ cin >> k; if(ufsuuji[k] != 0){ uyoko[ufsuuji[k]]++; if(uyoko[ufsuuji[k]]==n) ukotae++; utate[ussuuji[k]]++; if(utate[ussuuji[k]]==n) ukotae++; if(ufsuuji[k]==ussuuji[k]){ unaname[1]++; if(unaname[1]==n) ukotae++; } if(ufsuuji[k]+ussuuji[k]==n+1){ unaname[2]++; if(unaname[2]==n) ukotae++; } } if(nfsuuji[k] != 0){ nyoko[nfsuuji[k]]++; if(nyoko[nfsuuji[k]]==n) nkotae++; ntate[nssuuji[k]]++; if(ntate[nssuuji[k]]==n) nkotae++; if(nfsuuji[k]==nssuuji[k]){ nnaname[1]++; if(nnaname[1]==n) nkotae++; } if(nfsuuji[k]+nssuuji[k]==n+1){ nnaname[2]++; if(nnaname[2]==n) nkotae++; } } if(n==1){ ukotae = min(1,ukotae); nkotae = min(1,nkotae); } if(ukotae>=u && nkotae>=v){ cout << "DRAW" << endl; return 0; } else if(ukotae>=u){ cout << "USAGI" << endl; return 0; } else if(nkotae>=v){ cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <cassert> #include <string> #include <memory.h> #include <queue> #include <cstdio> #include <cstdlib> #include <set> #include <map> #include <cctype> #include <iomanip> #include <sstream> #include <cctype> #include <fstream> #include <cmath> using namespace std; #define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++) #define REP(i, n) REP2(i, 0, n) #define ALL(c) (c).begin(), (c).end() #define ITER(c) __typeof((c).begin()) #define PB(e) push_back(e) #define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i) #define MP(a, b) make_pair(a, b) #define PARITY(n) ((n) & 1) typedef long long ll; typedef pair<ll, ll> P; const int INF = 1000 * 1000 * 1000 + 7; const double EPS = 1e-10; int win_turn(int n, const vector<int> &rows, const vector<int> &cols, const vector<int> &ps, int w){ if(n == 1 && w > 1) return ps.size(); vector<int> rc(n, 0); vector<int> cc(n, 0); int d1 = 0, d2 = 0; REP(i, ps.size()){ int r = rows[ps[i]]; int c = cols[ps[i]]; if(r >= 0 && c >= 0){ if(++rc[r] == n) w--; if(++cc[c] == n) w--; if(r == c && ++d1 == n) w--; if(r + c + 1 == n && ++d2 == n) w--; } if(w <= 0){ // cout << i << endl; return i; } } return ps.size(); } int main(){ int n, m, u, v, p; cin >> n >> u >> v >> m; const int PMAX = 1000 * 1000; vector<int> ur(PMAX, -1), uc(PMAX, -1); vector<int> nr(PMAX, -1), nc(PMAX, -1); vector<int> ps(m); REP(i, n)REP(j, n){ cin >> p; --p; ur[p] = i; uc[p] = j; } REP(i, n)REP(j, n){ cin >> p; --p; nr[p] = i; nc[p] = j; } REP(i, m) { cin >> ps[i]; ps[i]--; } int uw = win_turn(n, ur, uc, ps, u); int nw = win_turn(n, nr, nc, ps, v); if(uw < nw){ cout << "USAGI" << endl; }else if(uw > nw){ cout << "NEKO" << endl; }else{ cout << "DRAW" << endl; } return 0; }
// template {{{ #include <bits/stdc++.h> using namespace std; #define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) loop(i, 0, n) #define rloop(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--) #define rrep(i, n) rloop(i, 0, n) #define pb push_back #define pf push_front #define eb emplace_back #define ef emplace_front #define mp std::make_pair #define mt std::make_tuple #define fi first #define se second using ll = long long; using ull = unsigned long long; template<typename T, size_t H, size_t W> using matrix = std::array<std::array<T, W>, H>; const int MOD = 1e9 + 7; const int INF = 1e9 + 10; const ll LLINF = 1e18 + 10; const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dy[] = {0, -1, 0, 1, -1, 1, -1, 1}; template<typename T> inline T sq(T x){ return x * x; } template<typename T, typename U> inline void chmax(T &x, U y){ x = std::max<T>(x, y); } template<typename T, typename U> inline void chmin(T &x, U y){ x = std::min<T>(x, y); } template<typename T> inline void sort(T &c){ std::sort(std::begin(c), std::end(c)); } template<typename T> inline void reverse(T &c){ std::reverse(std::begin(c), std::end(c)); } template<typename T> inline void unique(T &c){ sort(c); c.erase(std::unique(std::begin(c), std::end(c)), std::end(c)); } // }}} int n, u[2], m; int a[2][500][500], b[100000]; int cx[2][500], cy[2][500], cz[2][2]; vector<int> vx[2][100000], vy[2][100000], vz[2][100000]; int main() { cin >> n >> u[0] >> u[1] >> m; vector<int> z; rep(i, 2) rep(j, n) rep(k, n){ cin >> a[i][j][k]; } rep(i, m){ cin >> b[i]; z.pb(b[i]); } z.pb(INF); unique(z); rep(i, 2) rep(j, n) rep(k, n){ int t = lower_bound(begin(z), end(z), a[i][j][k]) - begin(z); if (a[i][j][k] != z[t]) continue; vx[i][t].pb(j); if (n > 1){ vy[i][t].pb(k); if (j == k) vz[i][t].pb(0); if (j + k == n - 1) vz[i][t].pb(1); } } string res = "DRAW"; rep(i, m){ int t = lower_bound(begin(z), end(z), b[i]) - begin(z); rep(j, 2){ for (int k : vx[j][t]){ if (++cx[j][k] == n) u[j]--; } for (int k : vy[j][t]){ if (++cy[j][k] == n) u[j]--; } for (int k : vz[j][t]){ if (++cz[j][k] == n) u[j]--; } } if (u[0] <= 0 && u[1] <= 0) break; if (u[0] <= 0){ res = "USAGI"; break; } if (u[1] <= 0){ res = "NEKO"; break; } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() const int mod=1000000007,MAX=105; const ll INF=1LL<<62; int main(){ std::ifstream in("text.txt"); std::cin.rdbuf(in.rdbuf()); cin.tie(0); ios::sync_with_stdio(false); int N,u,v,M;cin>>N>>u>>v>>M; vector<int> cnt1h(N),cnt1w(N),cnt2h(N),cnt2w(N); int cnt1=0,cnt2=0,cnt1x=0,cnt1y=0,cnt2x=0,cnt2y=0; vector<pair<int,int>> where1(1000000,{-1,-1}),where2(1000000,{-1,-1}); for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ int a;cin>>a; a--; where1[a]={i,j}; } } for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ int a;cin>>a; a--; where2[a]={i,j}; } } if(N==1){ while(M--){ int a,h,w;cin>>a; a--; if(where1[a].first>=0){ h=where1[a].first; w=where1[a].second; cnt1h[h]++; cnt1w[w]++; if(h==w) cnt1x++; if(h+w==N-1) cnt1y++; if(cnt1h[h]==N) cnt1++; //if(cnt1w[w]==N) cnt1++; //if(h==w&&cnt1x==N) cnt1++; //if(h+w==N-1&&cnt1y==N) cnt1y++; } if(where2[a].first>=0){ h=where2[a].first; w=where2[a].second; cnt2h[h]++; cnt2w[w]++; if(h==w) cnt2x++; if(h+w==N-1) cnt2y++; if(cnt2h[h]==N) cnt2++; //if(cnt2w[w]==N) cnt2++; //if(h==w&&cnt2x==N) cnt2++; //if(h+w==N-1&&cnt2y==N) cnt2y++; } if(cnt1>=u&&cnt2>=v){ cout<<"DRAW"<<endl; return 0; }else if(cnt1>=u){ cout<<"USAGI"<<endl; return 0; }else if(cnt2>=v){ cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; return 0; } while(M--){ int a,h,w;cin>>a; a--; if(where1[a].first>=0){ h=where1[a].first; w=where1[a].second; cnt1h[h]++; cnt1w[w]++; if(h==w) cnt1x++; if(h+w==N-1) cnt1y++; if(cnt1h[h]==N) cnt1++; if(cnt1w[w]==N) cnt1++; if(h==w&&cnt1x==N) cnt1++; if(h+w==N-1&&cnt1y==N) cnt1++; } if(where2[a].first>=0){ h=where2[a].first; w=where2[a].second; cnt2h[h]++; cnt2w[w]++; if(h==w) cnt2x++; if(h+w==N-1) cnt2y++; if(cnt2h[h]==N) cnt2++; if(cnt2w[w]==N) cnt2++; if(h==w&&cnt2x==N) cnt2++; if(h+w==N-1&&cnt2y==N) cnt2++; } if(cnt1>=u&&cnt2>=v){ cout<<"DRAW"<<endl; return 0; }else if(cnt1>=u){ cout<<"USAGI"<<endl; return 0; }else if(cnt2>=v){ cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; }
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<sstream> #include<string> #include<vector> #include<queue> #include<set> #include<map> #include<utility> #include<numeric> #include<algorithm> #include<bitset> #include<complex> #include<stack> using namespace std; typedef long long Int; typedef vector<int> vint; typedef pair<int,int> pint; typedef vector<string> vstring; struct Edge{int to,from,cost;}; template<class T> void chmin(T &t, T f) { if (t > f) t = f; } template<class T> void chmax(T &t, T f) { if (t < f) t = f; } int in() { int x; scanf("%d", &x); return x; } #define rep(i,n) for(int i=0;i<(n);++i) #define rep0(i,n) for(i=0;i<(n);++i) #define repn(i,m,n) for(int i=(m);i<=(n);++i) #define all(n) n.begin(),n.end() #define sz(n) ((int)(n).size()) #define mp make_pair #define PUTLINE cout<<"LINE:"<<__LINE__<<endl; const int INF = 2147483647; const double EPS = 1e-10; const double PI = acos(-1.0); const int dx[]={1,-1,0,0,1,-1,1,-1,0}; const int dy[]={0,0,1,-1,1,-1,-1,1,0}; int us[510][510]; int ne[510][510]; int usa[510][510]; int nek[510][510]; pint usag[1000100]; pint neko[1000100]; int n,u,v,m; bool inside(pint p){ return 0<=p.first&&p.first<n&&0<=p.second&&p.second<n; } int main() { cin>>n>>u>>v>>m; rep(i,1000100){ usag[i].first=usag[i].second=-1; neko[i].first=neko[i].second=-1; } rep(i,n)rep(j,n){ cin>>usa[i][j]; usag[usa[i][j]].first=j; usag[usa[i][j]].second=i; } rep(i,n)rep(j,n){ cin>>nek[i][j]; neko[nek[i][j]].first=j; neko[nek[i][j]].second=i; } int uc=0,nc=0; rep(i,m){ int a=in(),c; pint p; if(usag[a].first>=0){ us[usag[a].second][usag[a].first]=1; if(n>1){ rep(j,4){ c=0; for(p=usag[a];inside(p);p.first+=dx[2*j],p.second+=dy[2*j]){ if(us[p.second][p.first])++c; else break; } for(p=usag[a];inside(p);p.first+=dx[2*j+1],p.second+=dy[2*j+1]){ if(us[p.second][p.first])++c; else break; } if(c>n)++uc; } }else{ ++uc; } } if(neko[a].first>=0){ ne[neko[a].second][neko[a].first]=1; if(n>1){ rep(j,4){ c=0; for(p=neko[a];inside(p);p.first+=dx[2*j],p.second+=dy[2*j]){ if(ne[p.second][p.first])++c; else break; } for(p=neko[a];inside(p);p.first+=dx[2*j+1],p.second+=dy[2*j+1]){ if(ne[p.second][p.first])++c; else break; } if(c>n)++nc; } }else{ ++nc; } } if(uc>=u&&nc<v){ cout<<"USAGI"<<endl; return 0; } if(uc<u&&nc>=v){ cout<<"NEKO"<<endl; return 0; } if(uc>=u&&nc>=v)break; } cout<<"DRAW"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n,u,v,m,in,ru,cu,rn,cn,countu=0,countn=0; bool uw=false,nw=false; cin>>n>>u>>v>>m; vector<int> rowu(n,0),colu(n,0),crsu(2,0),rown(n,0),coln(n,0),crsn(2,0); vector<pair<int,int>> dicu(1000000,make_pair(-1,-1)),dicn(1000000,make_pair(-1,-1)); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>in; dicu[in-1]=make_pair(i,j); } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin>>in; dicn[in-1]=make_pair(i,j); } } for(int i=0;i<m;i++){ cin>>in; ru=dicu[in-1].first; cu=dicu[in-1].second; if(!(ru==-1||cu==-1)){ rowu[ru]++; if(rowu[ru]==n)countu++; colu[cu]++; if(colu[cu]==n&&n!=1)countu++; if(ru==cu){ crsu[0]++; if(crsu[0]==n&&n!=1)countu++; } if(n-1==ru+cu){ crsu[1]++; if(crsu[1]==n&&n!=1)countu++; } } rn=dicn[in-1].first; cn=dicn[in-1].second; if(!(rn==-1||cn==-1)){ rown[rn]++; if(rown[rn]==n)countn++; coln[cn]++; if(coln[cn]==n&&n!=1)countn++; if(rn==cn){ crsn[0]++; if(crsn[0]==n&&n!=1)countn++; } if(n-1==rn+cn){ crsn[1]++; if(crsn[1]==n&&n!=1)countn++; } } if(countu>=u)uw=true; if(countn>=v)nw=true; if(uw&&nw){ cout<<"DRAW"<<endl; return 0; } if(uw){ cout<<"USAGI"<<endl; return 0; } if(nw){ cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; return 0; }
#include <stdio.h> #include <cmath> #include <algorithm> #include <cfloat> #include <stack> #include <queue> #include <vector> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; int diff_row_hidariue[3] = {0,1,1},diff_col_hidariue[3] = {1,0,1}; int diff_row_migiue[2] = {1,1},diff_col_migiue[2] = {-1,0}; int n,u,v,m; struct Info{ int row,col,value; bool exist,checked; }; struct Data{ Data(int arg_row,int arg_col){ row = arg_row; col = arg_col; } int row,col; }; bool rangeCheck(int row,int col){ if(row >= 0 && row <= n-1 && col >= 0 && col <= n-1)return true; else{ return false; } } int main(){ scanf("%d %d %d %d",&n,&u,&v,&m); Info* loc_USAGI = (Info*)malloc(sizeof(Info)*(1000001)); Info* loc_NEKO = (Info*)malloc(sizeof(Info)*(1000001)); for(int i = 1; i <= 1000000; i++){ loc_USAGI[i].exist = false; loc_NEKO[i].exist = false; } Info** map_USAGI = (Info**)malloc(sizeof(Info*)*n); Info** map_NEKO = (Info**)malloc(sizeof(Info*)*n); for(int i = 0; i < n; i++){ map_USAGI[i] = (Info*)malloc(sizeof(Info)*n); map_NEKO[i] = (Info*)malloc(sizeof(Info)*n); } for(int row = 0; row < n; row++){ for(int col = 0; col < n; col++){ map_USAGI[row][col].checked = false; map_NEKO[row][col].checked = false; } } for(int row = 0; row < n; row++){ for(int col = 0; col < n; col++){ scanf("%d",&map_USAGI[row][col].value); loc_USAGI[map_USAGI[row][col].value].exist = true; loc_USAGI[map_USAGI[row][col].value].row = row; loc_USAGI[map_USAGI[row][col].value].col = col; } } for(int row = 0; row < n; row++){ for(int col = 0; col < n; col++){ scanf("%d",&map_NEKO[row][col].value); loc_NEKO[map_NEKO[row][col].value].exist = true; loc_NEKO[map_NEKO[row][col].value].row = row; loc_NEKO[map_NEKO[row][col].value].col = col; } } vector<Data> Usagi_D,Neko_D; int tmp,usagi_line,neko_line,count,start_row,start_col,tmp_row,tmp_col; bool usagi_FLG,neko_FLG; for(int loop = 0; loop < m; loop++){ scanf("%d",&tmp); usagi_FLG = false; neko_FLG = false; if(loc_USAGI[tmp].exist == true){ usagi_FLG = true; map_USAGI[loc_USAGI[tmp].row][loc_USAGI[tmp].col].checked = true; if(loc_USAGI[tmp].row == 0 || loc_USAGI[tmp].col == 0){ Usagi_D.push_back(Data(loc_USAGI[tmp].row,loc_USAGI[tmp].col)); } } if(loc_NEKO[tmp].exist == true){ neko_FLG = true; map_NEKO[loc_NEKO[tmp].row][loc_NEKO[tmp].col].checked = true; if(loc_NEKO[tmp].row == 0 || loc_NEKO[tmp].col == 0){ Neko_D.push_back(Data(loc_NEKO[tmp].row,loc_NEKO[tmp].col)); } } usagi_line = 0; if(usagi_FLG){ for(int i = 0; i < Usagi_D.size(); i++){ start_row = Usagi_D[i].row; start_col = Usagi_D[i].col; if(n > 1){ if(start_row == 0 && start_col == 0){ for(int k = 0; k < 3; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[k]; tmp_col = tmp_col + diff_col_hidariue[k]; } if(count >= n){ usagi_line++; } } }else if(start_row == 0 && start_col == n-1){ for(int k = 0; k < 2; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_migiue[k]; tmp_col = tmp_col + diff_col_migiue[k]; } if(count >= n){ usagi_line++; } } }else if(start_row == 0){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[1]; tmp_col = tmp_col + diff_col_hidariue[1]; } if(count >= n){ usagi_line++; } }else{ //tmp_col == 0 tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_USAGI[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[0]; tmp_col = tmp_col + diff_col_hidariue[0]; } if(count >= n){ usagi_line++; } } }else{ usagi_line = 1; } } } neko_line = 0; if(neko_FLG){ for(int i = 0; i < Neko_D.size(); i++){ start_row = Neko_D[i].row; start_col = Neko_D[i].col; if(n > 1){ if(start_row == 0 && start_col == 0){ for(int k = 0; k < 3; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[k]; tmp_col = tmp_col + diff_col_hidariue[k]; } if(count >= n){ neko_line++; } } }else if(start_row == 0 && start_col == n-1){ for(int k = 0; k < 2; k++){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_migiue[k]; tmp_col = tmp_col + diff_col_migiue[k]; } if(count >= n){ neko_line++; } } }else if(start_row == 0){ tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[1]; tmp_col = tmp_col + diff_col_hidariue[1]; } if(count >= n){ neko_line++; } }else{ //tmp_col == 0 tmp_row = start_row; tmp_col = start_col; count = 0; while(rangeCheck(tmp_row,tmp_col) == true && map_NEKO[tmp_row][tmp_col].checked == true){ count++; tmp_row = tmp_row + diff_row_hidariue[0]; tmp_col = tmp_col + diff_col_hidariue[0]; } if(count >= n){ neko_line++; } } }else{ neko_line = 1; } } } if(usagi_line >= u && neko_line >= v){ printf("DRAW\n"); return 0; }else if(usagi_line >= u && neko_line < v){ printf("USAGI\n"); return 0; }else if(usagi_line < u && neko_line >= v){ printf("NEKO\n"); return 0; } } printf("DRAW\n"); return 0; }
/* 05:55 - 06:20 first leg 06:20 - */ #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 For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i)) #define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; typedef pair<lint, lint> pll; template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;} template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;} template<class T> T div_floor(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>=0 ? a/b : (a+1)/b-1; } template<class T> T div_ceil(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>0 ? (a-1)/b+1 : a/b; } constexpr lint mod = 1000000007; constexpr lint INF = mod * mod; constexpr int MAX = 100010; int main(){ int n, u[2], m; scanf("%d%d%d%d", &n, &u[0], &u[1], &m); int a[2][n][n]; map<int, pii> pos[2]; rep(k, 2)rep(i, n)rep(j, n){ scanf("%d", &a[k][i][j]); pos[k][a[k][i][j]] = {i, j}; } int row[2][n], col[2][n], diag[2][2], cnt[2]; rep(k, 2){ rep(i, n) row[k][i] = col[k][i] = 0; rep(i, 2) diag[k][i] = 0; cnt[k] = 0; } rep(t, m){ int x; scanf("%d", &x); rep(k, 2){ if(pos[k].find(x) != pos[k].end()){ int i, j; tie(i, j) = pos[k][x]; cnt[k] += (++row[k][i] == n); cnt[k] += (++col[k][j] == n); if(i == j) cnt[k] += (++diag[k][0] == n); if(i == n-1-j) cnt[k] += (++diag[k][1] == n); if(n == 1) chmin(cnt[k], 1); } } if(cnt[0] >= u[0]){ if(cnt[1] >= u[1]) puts("DRAW"); else puts("USAGI"); return 0; } else if(cnt[1] >= u[1]){ puts("NEKO"); return 0; } } puts("DRAW"); }
#include <iostream> #include <vector> #include <algorithm> #include <cstdio> #include <set> #include <tuple> #include <map> #include <cmath> #include <numeric> #include <utility> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef pair<ll, ll> Pl; typedef tuple<ll, ll, ll> Tl; #define REP(i,n) for(int i=0;i < n;i++) #define EACH(it,a) for(auto it=a.begin();it!=a.end();it++) int main() { int n,u,v,m;cin >> n >> u >> v >> m; vector<vector<int>> us(n,vector<int>(n)),ns(n,vector<int>(n)); REP(y,n)REP(x,n) cin >> us[y][x]; REP(y,n)REP(x,n) cin >> ns[y][x]; map<int,pair<int,int>> umap,nmap; vector<int> ms(m); REP(i,m) cin >> ms[i]; REP(y,n)REP(x,n)umap[us[y][x]]=make_pair(y,x); REP(y,n)REP(x,n)nmap[ns[y][x]]=make_pair(y,x); int win=0;int uc=0,nc=0; vector<int> utate(n),uyoko(n);int ucross1=0,ucross2=0; vector<int> ntate(n),nyoko(n);int ncross1=0,ncross2=0; REP(i,m){ if(umap.count(ms[i])){ pair<int,int> p=umap[ms[i]]; int y=p.first,x=p.second; uyoko[y]++; if(uyoko[y]==n)uc++; utate[x]++; if(n>1 && utate[x]==n)uc++; if(n>1 && x+y==n-1){ ucross1++; if(ucross1==n)uc++; } if(n>1 && y-x==0){ ucross2++; if(ucross2==n)uc++; } } if(nmap.count(ms[i])){ pair<int,int> p=nmap[ms[i]]; int y=p.first,x=p.second; nyoko[y]++; if(nyoko[y]==n)nc++; ntate[x]++; if(n>1 && ntate[x]==n)nc++; if(n>1 && x+y==n-1){ ncross1++; if(ncross1==n)nc++; } if(n>1 && y-x==0){ ncross2++; if(ncross2==n)nc++; } } //cerr << i<<" "<<uc<<" "<<nc<<endl; if(uc>=u && nc<v)win=1; else if(uc<u && nc>=v)win=-1; } if(win==1) cout << "USAGI" << endl; if(win==-1) cout << "NEKO" << endl; if(win==0) cout << "DRAW" << endl; }
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <complex> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <iomanip> #include <assert.h> #include <array> #include <cstdio> #include <cstring> #include <random> #include <functional> #include <numeric> #include <bitset> #include <fstream> using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) int usagi[1000001]; int neko[1000001]; int Ru[500], Cu[500], Du[2]; int Rn[500], Cn[500], Dn[2]; int main() { int N, U, V, M; cin >> N >> U >> V >> M; rep(i, 1000001) usagi[i] = neko[i] = -1; rep(i, N) rep(j, N) { int x; scanf("%d", &x); usagi[x] = i * N + j; } rep(i, N) rep(j, N) { int x; scanf("%d", &x); neko[x] = i * N + j; } int u = 0, v = 0; rep(_, M) { int card; scanf("%d", &card); if(~usagi[card]) { int a = usagi[card] / N; Ru[a]++; int b = usagi[card] % N; Cu[b]++; if(a == b) Du[0]++; if(a == N-1-b) Du[1]++; if(Ru[a] == N) u++, Ru[a] = -1; if(Cu[b] == N) u++, Cu[b] = -1; if(Du[0] == N) u++, Du[0] = -1; if(Du[1] == N) u++, Du[1] = -1; } if(~neko[card]) { int a = neko[card] / N; Rn[a]++; int b = neko[card] % N; Cn[b]++; if(a == b) Dn[0]++; if(a == N-1-b) Dn[1]++; if(Rn[a] == N) v++, Rn[a] = -1; if(Cn[b] == N) v++, Cn[b] = -1; if(Dn[0] == N) v++, Dn[0] = -1; if(Dn[1] == N) v++, Dn[1] = -1; } if(N == 1) { u = min(1, u), v = min(1, v); if(!((u == 1 && U == 1) || (v == 1 && V == 1))) continue; if(u == 1 && v == 1 && U == V && U == 1) { cout << "DRAW" << endl; return 0; } else if(u == 1 && U == 1) { cout << "USAGI" << endl; return 0; } else if(v == 1 && V == 1) { cout << "NEKO" << endl; return 0; } else { cout << "DRAW" << endl; return 0; } } else if(U <= u && V > v) { cout << "USAGI" << endl; return 0; } else if(U > u && V <= v) { cout << "NEKO" << endl; return 0; } else if(U <= u && V <= v) { break; } } cout << "DRAW" << endl; return 0; }
#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; int n,u,v,m; int rabbit[1000010],cat[1000010]; int rnum=0,cnum=0; bool r[510][510]; bool c[510][510]; int main(void){ cin >> n >> u >> v >> m; clr(rabbit,-1),clr(cat,-1); rep(i,n*n){ int in; cin >> in; rabbit[in]=i; } rep(i,n*n){ int in; cin >> in; cat[in]=i; } int res=-1; rep(loop,m){ int in; cin >> in; if(rabbit[in]>=0){ r[rabbit[in]/n][rabbit[in]%n]=true; { bool ok=true; rep(j,n) if(r[rabbit[in]/n][j]==0) ok=false; rnum+=ok; } if(n!=1){ bool ok=true; rep(j,n) if(r[j][rabbit[in]%n]==0) ok=false; rnum+=ok; } if(n!=1&&rabbit[in]/n==rabbit[in]%n){ bool ok=true; rep(j,n) if(r[j][j]==0) ok=false; rnum+=ok; } if(n!=1&&rabbit[in]/n+rabbit[in]%n==n-1){ bool ok=true; rep(j,n) if(r[j][n-1-j]==0) ok=false; rnum+=ok; } } if(cat[in]>=0){ c[cat[in]/n][cat[in]%n]=true; { bool ok=true; rep(j,n) if(c[cat[in]/n][j]==0) ok=false; cnum+=ok; } if(n!=1){ bool ok=true; rep(j,n) if(c[j][cat[in]%n]==0) ok=false; cnum+=ok; } if(n!=1&&cat[in]/n==cat[in]%n){ bool ok=true; rep(j,n) if(c[j][j]==0) ok=false; cnum+=ok; } if(n!=1&&cat[in]/n+cat[in]%n==n-1){ bool ok=true; rep(j,n) if(c[j][n-1-j]==0) ok=false; cnum+=ok; } } if(res>=0) continue; if(rnum>=u&&cnum>=v) res=0; else if(rnum>=u) res=1; else if(cnum>=v) res=2; } if(res==1) cout << "USAGI" << endl; else if(res==2) cout << "NEKO" << endl; else cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> #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; //int usagi[510][510], neko[510][510]; map<int, pair<int, int>> usa_map, neko_map; set<int> usa_s, neko_s; cin>>n>>u>>v>>m; if(n==1){ int usa,neko; cin>>usa>>neko; REP(i,0,m){ int num; cin>>num; if(usa==num) usa_line++; if(neko==num) neko_line++; 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; } } p("DRAW"); return 0; } 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]; } 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> using namespace std; #define int long long #define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) using pii = pair<int, int>; signed main() { int n, u, v, m; cin >> n >> u >> v >> m; map<int,vector<pii>>usagi,neko; vector<vector<int>>usagi_vv(n,vector<int>(n)); auto neko_vv = usagi_vv; rep(i,0,n){ rep(j,0,n){ int x;cin>>x; usagi[x].emplace_back(i,j); usagi_vv[i][j]=x; } } rep(i,0,n){ rep(j,0,n){ int x;cin>>x; neko[x].emplace_back(i,j); neko_vv[i][j]=x; } } vector<int>card(m); rep(i,0,m)cin>>card[i]; auto simulate=[&](int turn,map<int,vector<pii>>&mp,vector<vector<int>>&vv){ vector<vector<bool>>ok(n,vector<bool>(n,false)); rep(i,0,turn){ int c=card[i]; for(auto &p:mp[c]){ int x,y; tie(x,y)=p; ok[x][y]=true; } } set<set<int>>st; int score=0; rep(i,0,n){ int cnt=0; set<int>tmp; rep(j,0,n){ if(ok[i][j]){ tmp.insert(vv[i][j]); } } if(tmp.size()==n)st.insert(tmp); } rep(j,0,n){ int cnt=0; set<int>tmp; rep(i,0,n){ if(ok[i][j]){ tmp.insert(vv[i][j]); } } if(tmp.size()==n)st.insert(tmp); } set<int>tmp; rep(i,0,n){ if(ok[i][i])tmp.insert(vv[i][i]); } if(tmp.size()==n)st.insert(tmp); tmp.clear(); rep(i,0,n){ if(ok[i][n-1-i])tmp.insert(vv[i][n-1-i]); } if(tmp.size()==n)st.insert(tmp); return st.size(); }; int x = simulate(m,usagi,usagi_vv)<u; int y = simulate(m,neko,neko_vv)<v; //cout<<"x:"<<x<<", y: "<<y<<endl; if( x && y){ cout<<"DRAW"<<endl; return 0; } else if(x){ cout<<"NEKO"<<endl; return 0; } else if(y){ cout<<"USAGI"<<endl; return 0; } auto bs=[&](map<int,vector<pii>>&mp,int z,vector<vector<int>>&vv){ int l=1,r=m; while(r-l>1){ int mid=(l+r)/2; if(simulate(mid,mp,vv)>=z){ r=mid; } else{ l=mid; } } return r; }; int a=bs(usagi,u,usagi_vv); int b=bs(neko,v,neko_vv); // cout<<"a:"<<a<<", b: "<<b<<endl; if(a==b){ cout<<"DRAW"<<endl; } else if(a<b){ cout<<"USAGI"<<endl; } else{ cout<<"NEKO"<<endl; } return 0; }
#include<iostream> #include<vector> #include<map> using namespace std; #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) const int N = 500; class st{ public: int n,hit; int rc[N],cc[N];//row‚Æcol‚Å‘µ‚Á‚Ä‚¢‚é“z‚̐”B int n1,n2;//ŽÎ‚ßn1 i==j,n2 i+j == n-1 map<int,pair<int,int> > M; st(){} st(int tn,int thit):n(tn),hit(thit),n1(tn),n2(tn){ M.clear(); rep(i,n){ rc[i] = n; cc[i] = n; } } void set(){ rep(i,n){ rep(j,n){ int tmp;cin>>tmp;M[tmp] = make_pair(i,j); } } } bool isend(int val){//hitsˆÈã‚̃f[ƒ^‚ª‘µ‚Á‚½‚©‚ð”»’è‚·‚éB if (M.count(val) == 0)return false; int y = M[val].first,x = M[val].second; rc[y]--; cc[x]--; if (y == x)n1--; if (y+x == n-1)n2--; if (rc[y] == 0)hit--; if (n != 1){//n !=1 ‚ÌŽžˆÈŠO‚̏ˆ— if (cc[x] == 0)hit--;//Šes‚ɂ‚¢‚Ä’²‚ׂé if (n1 == 0)hit--,n1--;//ŽÎ‚߂𒲂ׂé if (n2 == 0)hit--,n2--;//ŽÎ‚߂𒲂ׂé } return hit <= 0; } void debug(){ cout <<"debug----------------------------" << endl; cout <<"hit " << hit << endl; cout <<"n1 " << n1 << endl; cout <<"n2 " << n2 << endl; rep(i,n)cout <<" " << cc[i];cout << endl; rep(i,n){ cout << rc[i] << endl; } cout << endl; } }; int main(){ int n,u,v,m; while(cin>>n>>u>>v>>m && n){ st usagi(n,u),neko(n,v); usagi.set(); neko.set(); vector<int> in(m); rep(i,m){cin>>in[i];} rep(i,m){ bool ur = usagi.isend(in[i]),nr = neko.isend(in[i]); //usagi.debug(); //neko.debug(); if (ur && nr){ cout <<"DRAW"<<endl; goto end; }else if (ur){ cout <<"USAGI" << endl; goto end; }else if (nr){ cout <<"NEKO"<<endl; goto end; } } //cout <<"hogehoge" << endl; cout <<"DRAW"<<endl; end:; } }
#include<iostream> #include<algorithm> using namespace std; int main(){ int n,uv[2],m; cin>>n>>uv[0]>>uv[1]>>m; if(n==1){ uv[0]*=4; uv[1]*=4; } static int x[2][1000001],y[2][1000001]; fill(x[0],x[2],-1); fill(y[0],y[2],-1); for(int i=0;i<2;i++){ for(int j=0;j<n;j++){ for(int k=0;k<n;k++){ int d; cin>>d; x[i][d]=k; y[i][d]=j; } } } int ny[2][500]={},nx[2][500]={},ns[2]={},nbs[2]={}; for(int i=0;i<m;i++){ int c; cin>>c; for(int p=0;p<2;p++){ if(x[p][c]>=0){ nx[p][x[p][c]]++; uv[p]-=nx[p][x[p][c]]==n; ny[p][y[p][c]]++; uv[p]-=ny[p][y[p][c]]==n; if(x[p][c]==y[p][c]){ nbs[p]++; uv[p]-=nbs[p]==n; } if(x[p][c]+y[p][c]==n-1){ ns[p]++; uv[p]-=ns[p]==n; } } } if(uv[0]<=0&&uv[1]<=0){ break; }else if(uv[0]<=0||uv[1]<=0){ cout<<((uv[1]<=0)?"NEKO":"USAGI")<<endl; return 0; } } cout<<"DRAW"<<endl; return 0; }
#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> using namespace std; #define int long long int const int INF = 1001001001001001LL; const int MOD = 1000000007; struct info{ map<int, pair<int, int> > m; vector<int> h; vector<int> w; int a, b; info(int n, vector<vector<int> > mat){ h.resize(n + 1, 0); w.resize(n + 1, 0); a = 0; b = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ m[mat[i][j]] = {i + 1, j + 1}; } } } }; signed main(){ int n, u, v, m; cin >> n >> u >> v >> m; if(n == 1){ u += 3; v += 3; } vector<vector<int> > a(n, vector<int> (n)); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> a[i][j]; info usa = info(n, a); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> a[i][j]; info neko = info(n, a); int ans = 0; set<int> hoge; for(int i = 0; i < m; i++){ int val; cin >> val; if(hoge.find(val) != hoge.end()) continue; hoge.insert(val); if(ans != 0) continue; int usa_i = usa.m[val].first; int usa_j = usa.m[val].second; int neko_i = neko.m[val].first; int neko_j = neko.m[val].second; usa.h[usa_i]++; if(usa_i != 0 && usa.h[usa_i] == n) u--; usa.w[usa_j]++; if(usa_i != 0 && usa.w[usa_j] == n) u--; if(usa_i != 0 && usa_i - usa_j == 0) usa.a++; if(usa_i != 0 && usa.a == n){ u--; usa.a++; } if(usa_i != 0 && usa_i + usa_j == n + 1) usa.b++; if(usa_i != 0 && usa.b == n){ u--; usa.b++; } neko.h[neko_i]++; if(neko_i != 0 && neko.h[neko_i] == n) v--; neko.w[neko_j]++; if(neko_i != 0 && neko.w[neko_j] == n) v--; if(neko_i != 0 && neko_i - neko_j == 0) neko.a++; if(neko_i != 0 && neko.a == n){ v--; neko.a++; } if(neko_i != 0 && neko_i + neko_j == n + 1) neko.b++; if(neko_i != 0 && neko.b == n){ v--; neko.b++; } if(u <= 0 && v > 0){ ans = 1; continue; }else if(u > 0 && v <= 0){ ans = 2; continue; }else if(u <= 0 && v <= 0){ ans = 3; continue; } } if(ans == 0 || ans == 3) cout << "DRAW" << endl; else if(ans == 2) cout << "NEKO" << endl; else cout << "USAGI" << endl; return 0; }
#include <vector> #include <iostream> using namespace std; int n, u, v, m, x; int main() { ios::sync_with_stdio(false); cin >> n >> u >> v >> m; vector<int> p1(1000000, -1), p2(1000000, -1); vector<int> q1(1000000, -1), q2(1000000, -1); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> x; x--; p1[x] = i; p2[x] = j; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> x; x--; q1[x] = i; q2[x] = j; } } int pret = 0, qret = 0; bool flag = false; vector<int> pc1(n, 0), pc2(n, 0); int pc3 = 0, pc4 = 0; vector<int> qc1(n, 0), qc2(n, 0); int qc3 = 0, qc4 = 0; while (m-- && !flag) { cin >> x; x--; if (p1[x] != -1) { pc1[p1[x]]++; if (pc1[p1[x]] == n) pret++; pc2[p2[x]]++; if (pc2[p2[x]] == n) pret++; if (p1[x] == p2[x]) { pc3++; if (pc3 == n) pret++; } if (p1[x] == n - p2[x] - 1) { pc4++; if (pc4 == n) pret++; } } if (q1[x] != -1) { qc1[q1[x]]++; if (qc1[q1[x]] == n) qret++; qc2[q2[x]]++; if (qc2[q2[x]] == n) qret++; if (q1[x] == q2[x]) { qc3++; if (qc3 == n) qret++; } if (q1[x] == n - q2[x] - 1) { qc4++; if (qc4 == n) qret++; } } if (n == 1) { if (pret > 1) pret = 1; if (qret > 1) qret = 1; } if (pret >= u && qret >= v) break; if (pret >= u) { cout << "USAGI" << endl; flag = true; } if (qret >= v) { cout << "NEKO" << endl; flag = true; } } if (!flag) cout << "DRAW" << endl; return 0; }
#include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <algorithm> #include <utility> #include <functional> #include <sstream> #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <climits> #include <fstream> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;} template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();} 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 FOR(i,a,b) for(int i=(a);i<=(b);++i) #define REP(i,n) FOR(i,0,(n)-1) const double EPS = 1e-12; const double PI = acos(-1.0); const int INF = INT_MAX/10; int main() { int n, u, v, m; cin >> n >> u >> v >> m; int tmp; map<int, pii> um, nm; REP(i, n) { REP(j, n) { cin >> tmp; um[tmp] = make_pair(i+1, j+1); } } REP(i, n) { REP(j, n) { cin >> tmp; nm[tmp] = make_pair(i+1, j+1); } } vi ux(n, n), uy(n, n), uc(2, n); vi nx(n, n), ny(n, n), nc(2, n); bool uw = false, nw = false; REP(i, m) { cin >> tmp; if(um[tmp].first) { if(--ux[um[tmp].first-1] == 0) { --u; } if(--uy[um[tmp].second-1] == 0) { --u; } if(um[tmp].first == um[tmp].second) { if(--uc[0] == 0) { --u; } } if(um[tmp].first+um[tmp].second == n+1) { if(--uc[1] == 0) { --u; } } } if(u <= 0) { uw = true; if(n == 1 && u != -3) { uw = false; } } if(nm[tmp].first) { if(--nx[nm[tmp].first-1] == 0) { --v; } if(--ny[nm[tmp].second-1] == 0) { --v; } if(nm[tmp].first == nm[tmp].second) { if(--nc[0] == 0) { --v; } } if(nm[tmp].first+nm[tmp].second == n+1) { if(--nc[1] == 0) { --v; } } } if(v <= 0) { nw = true; if(n == 1 && v != -3) { nw = false; } } if(uw & nw) { cout << "DRAW" << endl; return 0; } if(uw) { cout << "USAGI" << endl; return 0; } if(nw) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <ctime> #include <vector> #include <string> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <functional> #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 BW(a,x,b) ((a)<=(x)&&(x)<=(b)) #define ALL(v) (v).begin(), (v).end() #define LENGTHOF(x) (sizeof(x) / sizeof(*(x))) #define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b) #define SQ(x) ((x)*(x)) #define Mod(x, mod) (((x)+(mod)%(mod)) #define MP make_pair #define PB push_back #define Fi first #define Se second #define INF (1<<29) #define EPS 1e-10 #define MOD 1000000007 typedef pair<int, int> pi; typedef pair<int, pi> pii; typedef vector<int> vi; typedef queue<int> qi; typedef long long ll; 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); } // cout << ru << " " << rn << endl; 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 <bits/stdc++.h> using namespace std; typedef pair<int, int> P; P usagi[1000001], neko[1000001]; int urow[505], ucol[505], udia[2], uwin; int nrow[505], ncol[505], ndia[2], nwin; int n, u, v, m; int main() { fill(usagi, usagi+1000001, P(-1, -1)); fill( neko, neko+1000001, P(-1, -1)); cin >> n >> u >> v >> m; for(int t = 0; t < 2; t++) { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { int num; cin >> num; (t ? neko[num] : usagi[num]) = P(i, j); } } } for(int i = 0; i < m; i++) { int card; cin >> card; if(~usagi[card].first) { P p = usagi[card]; if(n == 1) { uwin++; } else { urow[p.first]++, uwin += (urow[p.first] == n); ucol[p.second]++, uwin += (ucol[p.second] == n); if(p.first == p.second) udia[0]++, uwin += (udia[0] == n); if(p.first == n-1-p.second) udia[1]++, uwin += (udia[1] == n); } } if(~neko[card].first) { P p = neko[card]; if(n == 1) { nwin++; } else { nrow[p.first]++, nwin += (nrow[p.first] == n); ncol[p.second]++, nwin += (ncol[p.second] == n); if(p.first == p.second) ndia[0]++, nwin += (ndia[0] == n); if(p.first == n-1-p.second) ndia[1]++, nwin += (ndia[1] == n); } } if(u <= uwin && v <= nwin) { cout << "DRAW" << endl; return 0; } else if(u <= uwin) { cout << "USAGI" << endl; return 0; } else if(v <= nwin) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include "bits/stdc++.h" #pragma warning(disable:4996) using namespace std; const int My_Inf=2147483647; const long long int My_LInf=9223372036854775807; int N, U, V, M; struct bingo { map<int, int>wmp; map<int, int>hmp; set<int>slant00mp; set<int>slant0nmp; vector<int>wnum; vector<int>hnum; int slant00num; int slant0nnum; int ans; int need; bingo(int n,int need_):wnum(n),hnum(n){ need = need_; slant00num = 0; slant0nnum=0; ans = 0; } bool fill(int a) { if (wmp.count(a)) { wnum[wmp[a]]++; if (wnum[wmp[a]] == N)ans++; } if (hmp.count(a)) { hnum[hmp[a]]++; if (hnum[hmp[a]] == N)ans++; } if (slant00mp.count(a)) { slant00num++; if (slant00num == N)ans++; } if (slant0nmp.count(a)) { slant0nnum++; if (slant0nnum == N)ans++; } if (N == 1)ans = min(ans, 1); return need <= ans; } }; int main() {cin >> N >> U >> V >> M; vector<bingo>bingos; bingos.push_back(bingo(N, U)); bingos.push_back(bingo(N, V)); for (int k = 0; k < 2; ++k) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { int a; cin >> a; bingos[k].wmp[a] = i; bingos[k].hmp[a] = j; if (i == j)bingos[k].slant00mp.emplace(a); if (i + j == N - 1)bingos[k].slant0nmp.emplace(a); } } } while (M--) { int a; cin >> a; if (bingos[0].fill(a)) { if (bingos[1].fill(a)) { cout << "DRAW" << endl; return 0; } else { cout << "USAGI" << endl; return 0; } } else { if (bingos[1].fill(a)) { cout << "NEKO" << endl; return 0; } else { } } } cout << "DRAW" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; //repetition #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) //container util #define all(x) (x).begin(),(x).end() //typedef typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VLL; typedef vector<VLL> VVLL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; //const value //const ll MOD = 1e9 + 7; //const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1}; //const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1}; //conversion inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,u,v,m; cin >> n >> u >> v >> m; if(n == 1){ int ub,nb; int ucnt = 0, ncnt = 0; cin >> ub >> nb; rep(i,n){ int x; cin >> x; if(x == ub) ucnt++; if(x == nb) ncnt++; if(ucnt >= u && ncnt >= v){ cout << "DRAW" << "\n"; return 0;} if(ucnt >= u){cout << "USAGI" << "\n"; return 0;} if(ncnt >= v){cout << "NEKO" << "\n"; return 0;} } cout << "DRAW" << "\n"; return 0; } map<int,vector<PII>> umap; rep(i,n)rep(j,n){ int x; cin >> x; umap[x].push_back({i,j}); } map<int,vector<PII>> nmap; rep(i,n)rep(j,n){ int x; cin >> x; nmap[x].push_back({i,j}); } VI ui(n,0); VI uj(n,0); int ucross=0; int ucross2=0; VI ni(n,0); VI nj(n,0); int ncross=0; int ncross2=0; int nline = 0; int uline = 0; PII p; rep(i,m){ int x; cin >> x; bool nok=false, uok= false; //うさぎ if(umap.find(x) != umap.end()){ rep(i,umap[x].size()){ p = umap[x][i]; ui[p.first]++; if(ui[p.first] == n) uline++; uj[p.second]++; if(uj[p.second] == n) uline++; if(p.first == p.second) ucross++; if(ucross == n){uline++; ucross = -1e9;} if(p.first + p.second == n-1) ucross2++; if(ucross2 == n){uline++; ucross2 = -1e9;} if(uline >= u) uok = true; //cout << p.first << " "<< p.second << " -> " << uline << endl; } } //猫 if(nmap.find(x) != nmap.end()){ rep(i,nmap[x].size()){ p = nmap[x][i]; ni[p.first]++; if(ni[p.first] == n) nline++; nj[p.second]++; if(nj[p.second] == n) nline++; if(p.first == p.second) ncross++; if(ncross == n) {nline++; ncross = -1e9;} if(p.first + p.second == n-1) ncross2++;if(ncross2 == n) {nline++; ncross2 = -1e9;} if(nline >= v) nok = true; } } // cout << i << uline << " "<< nline<< endl; if(uok == true && nok == true){ cout << "DRAW" << "\n"; return 0;} if(uok){cout << "USAGI" << "\n"; return 0;} if(nok){cout << "NEKO" << "\n"; return 0;} } cout << "DRAW" << "\n"; return 0; }
#include <iostream> #include <cstdio> #include <vector> #include <set> #include <map> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <cstring> #include <functional> #include <cmath> #include <complex> using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define rep1(i,n) for(int i=1;i<=(n);++i) #define all(c) (c).begin(),(c).end() #define fs first #define sc second #define pb push_back #define show(x) cout << #x << " " << x << endl typedef pair<int,int> P; int n,u,v,m,a[500][500],b[500][500]; P x[1000001],y[1000001]; int ar[500],ac[500],br[500],bc[500],a1,a2,b1,b2,xx,yy; void inc(int &s,int r){ s++; if(s==n){ if(r==1) xx++; else yy++; } } int main(){ cin>>n>>u>>v>>m; if(n==1){ int o,s; cin>>o>>s; rep(i,m){ int c; cin>>c; if(o==c&&s==c&&u==1&&v==1){ puts("DRAW"); return 0; }else if(o==c&&u==1){ puts("USAGI"); return 0; }else if(s==c&&v==1){ puts("NEKO"); return 0; } } puts("DRAW"); return 0; } rep(i,1000001){ x[i]=y[i]=P(-1,-1); } rep(i,n) rep(j,n){ cin>>a[i][j]; x[a[i][j]]=P(i,j); } rep(i,n) rep(j,n){ cin>>b[i][j]; y[b[i][j]]=P(i,j); } rep(i,m){ int c; cin>>c; if(x[c].fs>=0){ int X=x[c].fs,Y=x[c].sc; inc(ar[X],1); inc(ac[Y],1); if(X==Y) inc(a1,1); if(X+Y==n-1) inc(a2,1); } if(y[c].fs>=0){ int X=y[c].fs,Y=y[c].sc; inc(br[X],2); inc(bc[Y],2); if(X==Y) inc(b1,2); if(X+Y==n-1) inc(b2,2); } if(xx>=u&&yy>=v){ puts("DRAW"); return 0; } if(xx>=u){ puts("USAGI"); return 0; } if(yy>=v){ puts("NEKO"); return 0; } } puts("DRAW"); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define int long long #define FOR(i, m, n) for (int i = (m); i < (n); i++) #define all(x) x.begin(), x.end() using pii = pair<int, int>; int A[505][505], B[505][505]; int rax[505], ray[505], rbx[505], rby[505]; void solve() { int N, U, V, M; cin >> N >> U >> V >> M; map<int, pii> mpA, mpB; int ra1 = N, ra2 = N, rb1 = N, rb2 = N; REP(i, N) { rax[i] = ray[i] = rbx[i] = rby[i] = N; } REP(i, N) { REP(j, N) { cin >> A[i][j]; mpA[A[i][j]] = {i, j}; } } REP(i, N) REP(j, N) { cin >> B[i][j]; mpB[B[i][j]] = {i, j}; } bool done = false; int result = 0; int cntA = 0, cntB = 0; if (N == 1) { REP(i, M) { int x; cin >> x; if (done) continue; if (mpA.count(x)) { pii p = mpA[x]; // cerr << "A:" << p.first << " " << p.second << endl; rax[p.first]--; ray[p.second]--; if (p.first == p.second) ra1--; else if (p.first == N - p.second - 1) ra2--; if (ra1 == 0) { // cerr << "ra1" << endl; ra1--; cntA++; } if (ra2 == 0) { // cerr << "ra2" << endl; ra2--; cntA++; } if (rax[p.first] == 0) cntA++; if (ray[p.second] == 0) cntA++; } if (mpB.count(x)) { pii p = mpB[x]; // cerr << "B:" << p.first << " " << p.second << endl; rbx[p.first]--; rby[p.second]--; if (p.first == p.second) rb1--; else if (p.first == N - p.second - 1) rb2--; if (rb1 == 0) { rb1--; cntB++; } if (rb2 == 0) { rb2--; cntB++; } if (rbx[p.first] == 0) cntB++; if (rby[p.second] == 0) cntB++; } // cerr << "cntA:" << cntA << endl; // cerr << "cntB:" << cntB << endl; if (cntA) cntA = 1; if (cntB) cntB = 1; if (cntA >= U && cntB >= V) { done = true; } else if (cntA >= U) { done = true; result = 1; } else if (cntB >= V) { done = true; result = 2; } } if (result == 0) cout << "DRAW"; else if (result == 1) cout << "USAGI"; else cout << "NEKO"; cout << endl; } else { REP(i, M) { int x; cin >> x; if (done) continue; if (mpA.count(x)) { pii p = mpA[x]; // cerr << "A:" << p.first << " " << p.second << endl; rax[p.first]--; ray[p.second]--; if (p.first == p.second) ra1--; if (p.first == N - p.second - 1) ra2--; if (ra1 == 0) { // cerr << "ra1" << endl; ra1--; cntA++; } if (ra2 == 0) { // cerr << "ra2" << endl; ra2--; cntA++; } if (rax[p.first] == 0) cntA++; if (ray[p.second] == 0) cntA++; } if (mpB.count(x)) { pii p = mpB[x]; // cerr << "B:" << p.first << " " << p.second << endl; rbx[p.first]--; rby[p.second]--; if (p.first == p.second) rb1--; if (p.first == N - p.second - 1) rb2--; if (rb1 == 0) { rb1--; cntB++; } if (rb2 == 0) { rb2--; cntB++; } if (rbx[p.first] == 0) cntB++; if (rby[p.second] == 0) cntB++; } // cerr << "cntA:" << cntA << endl; // cerr << "cntB:" << cntB << endl; // if (cntA >= U || cntB >= V) { // cerr << "cntA:" << cntA << endl; // cerr << "cntB:" << cntB << endl; // } if (cntA >= U && cntB >= V) { done = true; } else if (cntA >= U) { done = true; result = 1; } else if (cntB >= V) { done = true; result = 2; } } if (result == 0) cout << "DRAW"; else if (result == 1) cout << "USAGI"; else cout << "NEKO"; cout << endl; } } signed main() { // while (solve()) solve(); }
#include <iostream> #include <algorithm> #include <map> #include <cassert> using namespace std; const int MAXN = 502; const int MAXL = 1000005; int N, U[2], M; int X[2][MAXL], Y[2][MAXL]; int tate[2][MAXN], yoko[2][MAXN], migishita[2], migiue[2]; int main() { while(cin >> N >> U[0] >> U[1] >> M) { if(N == 1) { U[0] *= 4; U[1] *= 4; } fill(X[0], X[2], -1); fill(Y[0], Y[2], -1); for(int k = 0; k < 2; ++k) { for(int i = 0; i < N; ++i) { for(int j = 0; j < N; ++j) { int a; cin >> a; X[k][a] = j; Y[k][a] = i; } } } fill(tate[0], tate[2], 0); fill(yoko[0], yoko[2], 0); fill(migishita, migishita+2, 0); fill(migiue, migiue+2, 0); string res = ""; while(M--) { int a; cin >> a; if(res != "") continue; for(int k = 0; k < 2; ++k) { if(X[k][a] == -1) continue; U[k] -= ++tate[k][X[k][a]] == N; U[k] -= ++yoko[k][Y[k][a]] == N; if(X[k][a] == Y[k][a]) U[k] -= ++migishita[k] == N; if(X[k][a] == N-1-Y[k][a]) U[k] -= ++migiue[k] == N; } if(U[0] <= 0 || U[1] <= 0) { if(U[0] <= 0 && U[1] <= 0) res = "DRAW"; else if(U[0] <= 0) res = "USAGI"; else res = "NEKO"; } } if(res == "") res = "DRAW"; cout << res << endl; } return 0; }
#include <iostream> #include <vector> #include <string> #include <cstring> #include <algorithm> #include <sstream> #include <map> #include <set> #define REP(i,k,n) for(int i=k;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define INF 1<<30 #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int,int> P; int main() { int n, u, v, m; cin >> n >> u >> v >> m; map<int, vector<P> > ma[2]; vector<vector<int> > a(n, vector<int>(n)), b(n, vector<int>(n)); rep(i, n) { rep(j, n) { cin >> a[i][j]; ma[0][a[i][j]].push_back(mp(i, j)); } } rep(i, n) { rep(j, n) { cin >> b[i][j]; ma[1][b[i][j]].push_back(mp(i, j)); } } vector<int> x(m); rep(i, m) cin >> x[i]; if(n == 1) { rep(i, m) { int sum[2]; memset(sum, 0, sizeof(sum)); rep(j, 2) { vector<P> res = ma[j][x[i]]; if(res.size() >= 1) sum[j]++; } bool f1 = (sum[0] >= u); bool f2 = (sum[1] >= v); if(f1 && f2) { cout << "DRAW" << endl; return 0; } else if(f1) { cout << "USAGI" << endl; return 0; } else if(f2) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; } int cy[2][505], cx[2][505], cross[2][2]; memset(cy, 0, sizeof(cy)); memset(cx, 0, sizeof(cx)); memset(cross, 0, sizeof(cross)); rep(i, m) { rep(j, 2) { vector<P> res = ma[j][x[i]]; rep(k, res.size()) { int f = res[k].first, s = res[k].second; cy[j][f]++; cx[j][s]++; if(f == s) cross[j][0]++; if(f == n - 1 - s) cross[j][1]++; } } int sum[2]; memset(sum, 0, sizeof(sum)); rep(j, 2) { rep(k, 2) { sum[j] += (cross[j][k] == n); } } rep(j, 2) { rep(k, n) { sum[j] += (cy[j][k] == n); sum[j] += (cx[j][k] == n); } } bool f1 = (sum[0] >= u), f2 = (sum[1] >= v); if(f1 && f2) { cout << "DRAW" << endl; return 0; } else if(f1) { cout << "USAGI" << endl; return 0; } else if(f2) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; return 0; }
#include<bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long #define ALL(a) (a).begin(),(a).end() #define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl; #define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl; typedef struct aaaaa{ int x,y,t; }Grid; using namespace std; int main(){ int n,u,v,m; cin>>n>>u>>v>>m; int usa[2000]={}; int neko[2000]={}; map<int,pair<int,int> >hoge; map<int,pair<int,int> >hoge2; int uu=0,nn=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int a;cin>>a; hoge[a]=mp(i+1,j+1); } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int a;cin>>a; hoge2[a]=mp(i+1,j+1); } } bool hoho[2000]={}; bool gege[2000]={}; bool ho=false,ge=false; for(int i=0;i<m;i++){ int a;cin>>a; if(ho||ge)continue; if(hoge[a].F!=0&&hoge[a].S!=0){ usa[hoge[a].F]++; usa[hoge[a].S+510]++; if(usa[hoge[a].F]>=n&&!hoho[hoge[a].F]){ if(n!=1) uu++; hoho[hoge[a].F]=true; } if(usa[hoge[a].S+510]>=n&&!hoho[hoge[a].S+510]){ uu++; hoho[hoge[a].S+510]=true; } if(hoge[a].F==hoge[a].S){ usa[1500]++; } if(usa[1500]>=n&&!hoho[1500]){ if(n!=1) uu++; hoho[1500]=true; } if(hoge[a].F==abs(n-hoge[a].S+1)) usa[1501]++; if(usa[1501]>=n&&!hoho[1501]){ if(n!=1) uu++; hoho[1501]=true; } } if(hoge2[a].F!=0&&hoge2[a].S!=0){ neko[hoge2[a].F]++; neko[hoge2[a].S+510]++; if(neko[hoge2[a].F]>=n&&!gege[hoge2[a].F]){ nn++; gege[hoge2[a].F]=true; } if(neko[hoge2[a].S+510]>=n&&!gege[hoge2[a].S+510]){ if(n!=1) nn++; gege[hoge2[a].S+510]=true; } if(hoge2[a].F==hoge2[a].S){ neko[1500]++; } if(neko[1500]>=n&&!gege[1500]){ gege[1500]=true; if(n!=1) nn++; } if(hoge2[a].F==abs(n-hoge2[a].S+1)) neko[1501]++; if(neko[1501]>=n&&!gege[1501]){ if(n!=1) nn++; gege[1501]=true; } } // cout<<uu<<" "<<nn<<endl; if(uu>=u)ho=true; if(nn>=v)ge=true; } if(ho&&ge)cout<<"DRAW"<<endl; else if(ho)cout<<"USAGI"<<endl; else if(ge)cout<<"NEKO"<<endl; else cout<<"DRAW"<<endl; return 0; }
#include <iostream> #include <vector> using namespace std; int main() { for(int n,u,v,m;cin>>n>>u>>v>>m;){ vector<int> ris(1e6+1,-1),rjs=ris,cis=ris,cjs=rjs; for(int i=0;i<n;i++) for(int j=0;j<n;j++){ int x; cin>>x; ris[x]=i,rjs[x]=j; } for(int i=0;i<n;i++) for(int j=0;j<n;j++){ int x; cin>>x; cis[x]=i,cjs[x]=j; } vector<int> xs(m); for(int i=0;i<m;i++) cin>>xs[i]; int rcnt=0,ccnt=0; if(n==1){ // corner case for(int x:xs){ if(ris[x]!=-1) rcnt++; if(cis[x]!=-1) ccnt++; if(rcnt>=u && ccnt<v){ cout<<"USAGI"<<endl; goto end; } if(rcnt<u && ccnt>=v){ cout<<"NEKO"<<endl; goto end; } } } else{ vector<int> ric(n),rjc(n),rdc(2),cic(n),cjc(n),cdc(2); for(int x:xs){ if(ris[x]!=-1){ if(++ric[ris[x]]==n) rcnt++; if(++rjc[rjs[x]]==n) rcnt++; if(ris[x]==rjs[x] && ++rdc[0]==n) rcnt++; if(ris[x]==n-1-rjs[x] && ++rdc[1]==n) rcnt++; } if(cis[x]!=-1){ if(++cic[cis[x]]==n) ccnt++; if(++cjc[cjs[x]]==n) ccnt++; if(cis[x]==cjs[x] && ++cdc[0]==n) ccnt++; if(cis[x]==n-1-cjs[x] && ++cdc[1]==n) ccnt++; } if(rcnt>=u && ccnt<v){ cout<<"USAGI"<<endl; goto end; } if(rcnt<u && ccnt>=v){ cout<<"NEKO"<<endl; goto end; } } } cout<<"DRAW"<<endl; end:; } }
#include <iostream> #include <vector> #include <map> using namespace std; int main(void) { int n,u,v,m; cin >> n >> u >> v >> m; map<int,int> rcol,ccol; map<int,int> rrow,crow; map<int,bool> rdia,cdia; map<int,bool> rrdia,crdia; int temp; if (n > 1) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> temp; rcol[temp] = j + 1; rrow[temp] = i + 1; if (i == j) { rdia[temp] = true; } if (i+j == n-1) { rrdia[temp] = true; } } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> temp; ccol[temp] = j + 1; crow[temp] = i + 1; if (i == j) { cdia[temp] = true; } if (i+j == n-1) { crdia[temp] = true; } } } } else { cin >> temp; rdia[temp] = true; cin >> temp; cdia[temp] = true; } int card,rc,cc; vector<int> rc_col(n,0),cc_col(n,0); vector<int> rc_row(n,0),cc_row(n,0); vector<int> rc_dia(2,0),cc_dia(2,0); rc = cc = 0; bool fin = false; for (int i = 0; i < m; ++i) { cin >> card; if (!fin) { if (rcol[card] > 0) { ++rc_col[rcol[card]-1]; if (rc_col[rcol[card]-1] == n) { ++rc; } } if (rrow[card] > 0) { ++rc_row[rrow[card]-1]; if (rc_row[rrow[card]-1] == n) { ++rc; } } if (rdia[card]) { ++rc_dia[0]; if (rc_dia[0] == n) { ++rc; } } if (rrdia[card]) { ++rc_dia[1]; if (rc_dia[1] == n) { ++rc; } } if (ccol[card] > 0) { ++cc_col[ccol[card]-1]; if (cc_col[ccol[card]-1] == n) { ++cc; } } if (crow[card] > 0) { ++cc_row[crow[card]-1]; if (cc_row[crow[card]-1] == n) { ++cc; } } if (cdia[card]) { ++cc_dia[0]; if (cc_dia[0] == n) { ++cc; } } if (crdia[card]) { ++cc_dia[1]; if (cc_dia[1] == n) { ++cc; } } if (rc >= u && cc >= v) { cout << "DRAW" << endl; fin = true; } else if (rc >= u) { cout << "USAGI" << endl; fin = true; } else if (cc >= v) { cout << "NEKO" << endl; fin = true; } } } if (!fin) { cout << "DRAW" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int mat[2][510][510]; bool u[1001000]; vector<int> cards; int n,p[2],m; int f(int l,int id){ for(int i = 0 ; i < min<int>(cards.size(),l) ; i++) u[cards[i]]=true; int ans = 0; for(int i = 0 ; i < n ; i++){ int ok = 1; for(int j = 0 ; j < n ; j++) ok &= u[mat[id][i][j]]; ans += ok; if( n != 1 ){ ok = 1; for(int j = 0 ; j < n ; j++) ok &= u[mat[id][j][i]]; ans += ok; } } if( n != 1 ) { int ok = 1; for(int j = 0 ; j < n ; j++) ok &= u[mat[id][j][j]]; ans += ok; } if( n != 1 ) { int ok = 1; for(int j = 0 ; j < n ; j++) ok &= u[mat[id][n-j-1][j]]; ans += ok; } for(int i = 0 ; i < min<int>(cards.size(),l) ; i++) u[cards[i]]=false; return ans; } int bins(int id){ int l = 0 , r = m+1; while( l != r ){ int mi = (l+r)/2; if( f(mi,id) >= p[id] ) r = mi; else l = mi+1; } return l; } int main(){ cin >> n >> p[0] >> p[1] >> m; for(int j = 0 ; j < 2 ; j++){ for(int i = 0 ; i < n ; i++){ for(int k = 0 ; k < n ; k++){ scanf("%d",&mat[j][i][k]); } } } for(int i = 0 ; i < m ; i++){ int t; cin >> t; cards.push_back(t); } int a = bins(0); int b = bins(1); if( a == b ){ cout << "DRAW" << endl; }else if( a < b ){ cout << "USAGI" << endl; }else{ cout << "NEKO" << endl; } }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <sstream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <numeric> #include <cctype> #include <tuple> #include <array> // BEGIN CUT HERE #ifdef _MSC_VER #include <agents.h> #endif // END CUT HERE #define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep(i, n) FOR(i, 0, n) #define ALL(v) begin(v), end(v) #define REV(v) rbegin(v), rend(v) #define MEMSET(v, s) memset(v, s, sizeof(v)) #define MP make_pair #define MT make_tuple #define X first #define Y second using namespace std; typedef pair<int, int> P; typedef long long ll; const int N = 510, M = 1e5+10; P pos[2][M*10]; int x[M]; int n, u, v, m; int board[N][N]; bool check(int turn, P *pos, int uv){ MEMSET(board, 0); for (int i = 0; i < turn; ++i){ board[pos[x[i]].Y][pos[x[i]].X] = 1; } int cnt[2] = {}; FOR(i, 1, n+1){ if (board[i][i]) ++cnt[0]; if (board[i][n+1-i]) ++cnt[1]; } rep(i, n+1) rep(j, n+1){ board[i + 1][j] += board[i][j]; board[i][j + 1] += board[i][j]; board[i + 1][j + 1] -= board[i][j]; } int res = (cnt[0] == n) + (cnt[1] == n); FOR(i, 1, n+1){ if (board[i][n+1] == n) ++res; if (board[n+1][i] == n) ++res; } if (n == 1) res = !!res; return res >= uv; } int main(){ cin >> n >> u >> v >> m; rep(i, 2) rep(j, n) rep(k, n){ int xx; cin >> xx; pos[i][xx] = MP(k+1, j+1); } rep(i, m) cin >> x[i]; bool end = false; int lb = 0, ub = m+1; while (ub - lb > 1){ int mid = (ub + lb) / 2; bool usa = check(mid, pos[0], u); bool neko = check(mid, pos[1], v); if (usa != neko){ if (usa) cout << "USAGI" << endl; else cout << "NEKO" << endl; end = true; break; } if (usa) ub = mid; else lb = mid; } if (!end) cout << "DRAW" << 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 (1e9+1) //#define INF (1LL<<59) int n; int countBingo(vector<vector<bool>> &fie,int y,int x){ if(n==1)return 1; int c=0; bool f=true; rep(i,n) if(fie[y][i]==false)f=false; if(f)c++; f=true; rep(i,n) if(fie[i][x]==false)f=false; if(f)c++; if(x==y){ f=true; rep(i,n) if(fie[i][i]==false)f=false; if(f)c++; } if(y+x == n-1){ f=true; rep(i,n) if(fie[n-i-1][i]==false)f=false; if(f)c++; } return c; } int main(){ int u,v,m; cin>>n>>u>>v>>m; int usac=0,nekoc=0; vector<vector<bool>> usa(n,vector<bool>(n,false)),neko(n,vector<bool>(n,false)); map<int,pii> usamp,nekomp; rep(i,n)rep(j,n){ int a; cin>>a; usamp[a] = pii(i,j); } rep(i,n)rep(j,n){ int a; cin>>a; nekomp[a] = pii(i,j); } bool f=false; rep(i,m){ int num; cin>>num; if(f)continue; if(usamp.count(num)!=0){ pii p = usamp[num]; usa[p.first][p.second] = true; usac += countBingo(usa,p.first,p.second); } if(nekomp.count(num)!=0){ pii p = nekomp[num]; neko[p.first][p.second] = true; nekoc += countBingo(neko,p.first,p.second); } if(usac>=u&&nekoc>=v){ cout<<"DRAW"<<endl; f=true; }else if(usac>=u){ cout<<"USAGI"<<endl; f=true; }else if(nekoc>=v){ cout<<"NEKO"<<endl; f=true; } } // cout<<usac<<" "<<nekoc<<endl; if(f==false)cout<<"DRAW"<<endl; }
#include <map> #include <iostream> using namespace std; typedef pair<int, int> P; int main(){ int n,u,v,m,k; cin >> n >> u >> v >> m; 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(n==1){ if(usagi_n!=0&&1>=u) usagi_b=true; else usagi_b=false; if(neko_n!=0&&1>=v) neko_b=true; else neko_b=false; } 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; #define int long long #define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) using pii = pair<int, int>; signed main() { int n, u, v, m; cin >> n >> u >> v >> m; map<int, vector<pii>> pos[2]; vector<vector<bool>> ok[2]; ok[0].assign(n, vector<bool>(n, false)); ok[1].assign(n, vector<bool>(n, false)); vector<bool> skip_row[2]; skip_row[0].assign(n, false); skip_row[1].assign(n, false); vector<bool> skip_col[2]; skip_col[0].assign(n, false); skip_col[1].assign(n, false); vector<bool> skip_d[2]; skip_d[0].assign(2, false); skip_d[1].assign(2, false); int fin[2] = {}; rep(k, 0, 2) { rep(i, 0, n) { rep(j, 0, n) { int x; cin >> x; pos[k][x].push_back({i, j}); } } } vector<int> card(m); rep(i, 0, m) { cin >> card[i]; } auto check_row = [&](vector<vector<bool>> &ok, int r) { bool f = true; rep(i, 0, n) { if (!ok[r][i]) f = false; } return f; }; auto check_col = [&](vector<vector<bool>> &ok, int c) { bool f = true; rep(i, 0, n) { if (!ok[i][c]) f = false; } return f; }; auto check_d = [&](vector<vector<bool>> &ok, int p) { bool f = true; if (p) { rep(i, 0, n) { if (!ok[i][i]) { f = false; } } } else { rep(i, 0, n) { if (!ok[i][n - i - 1]) { f = false; } } } return f; }; int ans = -1; rep(i, 0, m) { rep(k, 0, 2) { for (pii p : pos[k][card[i]]) { int y, x; tie(y, x) = p; ok[k][y][x] = true; if (!skip_row[k][y] && check_row(ok[k], y)) { skip_row[k][y] = true; fin[k]++; } if (!skip_col[k][x] && check_col(ok[k], x)) { skip_col[k][x] = true; fin[k]++; } } if (!skip_d[k][0] && check_d(ok[k], 0)) { skip_d[k][0] = true; fin[k]++; } if (!skip_d[k][1] && check_d(ok[k], 1)) { skip_d[k][1] = true; fin[k]++; } if (n == 1 && fin[k] > 0) fin[k] = 1; } // cerr << "2: fin1: " << fin1 << ", fin2: " << fin2 << ", card[i]: " << card[i] << endl; if (fin[0] >= u && fin[1] >= v) { break; } if (fin[0] >= u) { ans = 0; break; } if (fin[1] >= v) { ans = 1; break; } } if (ans == -1) { cout << "DRAW" << endl; } else if (ans == 0) { cout << "USAGI" << endl; } else { cout << "NEKO" << endl; } return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstring> #include <cmath> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<ll, int> ll_i; typedef pair<double, int> d_i; typedef pair<ll, ll> ll_ll; typedef pair<double, double> d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-9; int dx[4] = {-1, -1, 0, 1}; int dy[4] = {0, -1, -1, -1}; bool check(int x, int y, vector< vector<int> >& a, int& num) { if (x == -1) return false; a[y][x] = 0; int n = a.size(); for (int k = 0; k < (n == 1 ? 1 : 4); k++) { int cnt = -1; for (int _x = x, _y = y; _x >= 0 && _x < n && _y >= 0 && _y < n && !a[_y][_x]; _x += dx[k], _y += dy[k]) cnt++; for (int _x = x, _y = y; _x >= 0 && _x < n && _y >= 0 && _y < n && !a[_y][_x]; _x -= dx[k], _y -= dy[k]) cnt++; if (cnt >= n) num++; } return false; } int main() { int n, u, v, m; cin >> n >> u >> v >> m; vector< vector<int> > a(n, vector<int>(n)), b = a; vector<int> xa(1000001, -1), ya = xa, xb = xa, yb = xa; for (int y = 0; y < n; y++) for (int x = 0; x < n; x++) { int k; cin >> k; a[y][x] = k; xa[k] = x; ya[k] = y; } for (int y = 0; y < n; y++) for (int x = 0; x < n; x++) { int k; cin >> k; b[y][x] = k; xb[k] = x; yb[k] = y; } int na = 0, nb = 0; while (m--) { int k; cin >> k; check(xa[k], ya[k], a, na); check(xb[k], yb[k], b, nb); bool fa = (na >= u), fb = (nb >= v); if (fa && fb) { cout << "DRAW" << endl; return 0; } if (fa && !fb) { cout << "USAGI" << endl; return 0; } if (!fa && fb) { cout << "NEKO" << endl; return 0; } } cout << "DRAW" << endl; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define repr(i,n) for(int i=(int)(n-1);i>=0;i--) #define rep(i,n) repl(i,0,n) #define each(itr,v) for(auto itr:v) #define pb(s) push_back(s) #define all(x) (x).begin(),(x).end() #define dbg(x) cout << #x" = " << x << endl #define print(x) cout << x << endl #define maxch(x,y) x=max(x,y) #define minch(x,y) x=min(x,y) #define uni(x) x.erase(unique(all(x)),x.end()) #define exist(x,y) (find(all(x),y)!=x.end()) #define bcnt(x) bitset<32>(x).count() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<P, int> PPI; typedef pair<int, P> PIP; typedef pair<ll, ll> PL; typedef pair<P, ll> PPL; typedef set<int> S; #define INF INT_MAX/3 #define MAX_N 1000000001 int n, u, v, m, tmp; P rr[1000001], cc[1000001]; int rx[500], ry[500], cx[500], cy[500], rcr[2], ccr[2]; int main(){ cin.sync_with_stdio(false); cin >> n >> u >> v >> m; fill(rr, rr + 1000001, P(-1, -1)); fill(cc, cc + 1000001, P(-1, -1)); rep(i, n)rep(j, n) { cin >> tmp; rr[tmp] = P(i, j); } rep(i, n)rep(j, n) { cin >> tmp; cc[tmp] = P(i, j); } int rp = 0, cp = 0; int wf = -1; rep(i, m) { int t; cin >> t; if (n > 1) { if (rr[t] != P(-1, -1)) { ry[rr[t].fi]++; if (ry[rr[t].fi] == n) rp++; rx[rr[t].se]++; if (rx[rr[t].se] == n) rp++; if (rr[t].fi == rr[t].se) rcr[0]++; if (rcr[0] == n) rp++, rcr[0]++; if (rr[t].fi + rr[t].se == n - 1) rcr[1]++; if (rcr[1] == n) rp++, rcr[1]++; } if (cc[t] != P(-1, -1)) { cy[cc[t].fi]++; if (cy[cc[t].fi] == n) cp++; cx[cc[t].se]++; if (cx[cc[t].se] == n) cp++; if (cc[t].fi == cc[t].se) ccr[0]++; if (ccr[0] == n) cp++, ccr[0]++; if (cc[t].fi + cc[t].se == n - 1) ccr[1]++; if (ccr[1] == n) cp++, ccr[1]++; } } else { if (rr[t] != P(-1, -1)) rp = 1; if (cc[t] != P(-1, -1)) cp = 1; } if (wf < 0 && rp >= u && cp >= v) wf = 0; else if (wf < 0 && rp >= u) wf = 1; else if (wf < 0 && cp >= v) wf = 2; } cout << ((wf <= 0) ? "DRAW" : ((wf == 1) ? "USAGI" : "NEKO")) << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define P pair<int,int> int n,u,v,m; int ux[510],uy[510]; int vx[510],vy[510]; int uu[2],vv[2]; map<int,P> mu,mv; int main(){ cin>>n>>u>>v>>m; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int a; cin>>a; mu[a]=P(i,j); } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ int a; cin>>a; mv[a]=P(i,j); } } int uc=0,vc=0; while(m--){ int a; cin>>a; // cout<<a<<endl; if(mu.find(a)!=mu.end()){ P pu=mu[a]; int x=pu.second,y=pu.first; // cout<<"u "<<x<<' '<<y<<endl; ux[x]++; uy[y]++; if(ux[x]==n) uc++; if(uy[y]==n&&n!=1) uc++; if(x==y&&n!=1){ uu[0]++; if(uu[0]==n) uc++; } if(x+y+1==n&&n!=1){ uu[1]++; if(uu[1]==n) uc++; } } if(mv.find(a)!=mv.end()){ P pv=mv[a]; int x=pv.second,y=pv.first; // cout<<"v "<<x<<' '<<y<<endl; vx[x]++; vy[y]++; if(vx[x]==n) vc++; if(vy[y]==n&&n!=1) vc++; if(x==y){ vv[0]++; if(vv[0]==n&&n!=1) vc++; } if(x+y+1==n){ vv[1]++; if(vv[1]==n&&n!=1) vc++; } } // cout<<uc<<' '<<vc<<endl; if(uc>=u&&vc>=v){ cout<<"DRAW"<<endl; return 0; } if(uc>=u){ cout<<"USAGI"<<endl; return 0; } if(vc>=v){ cout<<"NEKO"<<endl; return 0; } } cout<<"DRAW"<<endl; }
#include "bits/stdc++.h" #define REP(i,n) for(ll i=0;i<ll(n);++i) #define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i) #define FOR(i,m,n) for(ll i=m;i<ll(n);++i) #define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i) #define ALL(v) (v).begin(),(v).end() #define UNIQUE(v) v.erase(unique(ALL(v)),v.end()); #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 }; constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 }; using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, u, v, m; cin >> n >> u >> v >> m; map<int, pii> a, b; REP(i, n)REP(j, n) { int c; cin >> c; a[c] = { i,j }; } REP(i, n)REP(j, n) { int c; cin >> c; b[c] = { i,j }; } vi ra(n, 0), ca(n, 0), rb(n, 0), cb(n, 0); int cnta = 0, cntb = 0, da1 = 0, da2 = 0, db1 = 0, db2 = 0; bool done = false; REP(aaa, m) { int num; cin >> num; if (a.count(num)) { int x, y; tie(x, y) = a[num]; if (++ra[x] == n)cnta++; if (++ca[y] == n)cnta++; if (x + y == n - 1 && ++da1 == n)cnta++; if (x == y && ++da2 == n)cnta++; } if (b.count(num)) { int x, y; tie(x, y) = b[num]; if (++rb[x] == n)cntb++; if (++cb[y] == n)cntb++; if (x + y == n - 1 && ++db1 == n)cntb++; if (x == y && ++db2 == n)cntb++; } if (n == 1) { chmin(cnta, 1); chmin(cntb, 1); } if (cnta >= u && cntb >= v) { cout << "DRAW" << endl; done = true; break; } else if (cnta >= u) { cout << "USAGI" << endl; done = true; break; } else if(cntb>=v) { cout << "NEKO" << endl; done = true; break; } } if (!done) { cout << "DRAW" << endl; } }
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <math.h> #include <assert.h> #include <vector> #include <queue> #include <string> #include <map> #include <set> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; static const double EPS = 1e-9; static const double PI = acos(-1.0); #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, s, n) for (int i = (s); i < (int)(n); i++) #define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++) #define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++) #define MEMSET(v, h) memset((v), h, sizeof(v)) int matrix[2][510][510]; int ok[2][510][510]; int cnt[2]; int card[100010]; int px[2][1000010]; int py[2][1000010]; int n, u, v, m; int Check(int iter, int sx, int sy, int dx, int dy) { int sum = 0; REP(i, n) { sum += ok[iter][sy + dy * i][sx + dx * i]; } return sum == n; } int main() { while (scanf("%d %d %d %d", &n, &u, &v, &m) > 0) { MEMSET(px, -1); MEMSET(py, -1); MEMSET(cnt, 0); MEMSET(ok, 0); REP(iter, 2) { REP(y, n) { REP(x, n) { scanf("%d", &matrix[iter][y][x]); px[iter][matrix[iter][y][x]] = x; py[iter][matrix[iter][y][x]] = y; } } } REP(i, m) { scanf("%d", &card[i]); } if (n == 1) { REP(i, m) { REP(iter, 2) { if (matrix[iter][0][0] == card[i]) { cnt[iter]++; } } if (cnt[0] >= u || cnt[1] >= v) { goto end; } } } else { REP(i, m) { int c = card[i]; REP(iter, 2) { int tx = px[iter][c]; int ty = py[iter][c]; if (tx == -1) { continue; } ok[iter][ty][tx] = 1; cnt[iter] += Check(iter, tx, 0, 0, 1); cnt[iter] += Check(iter, 0, ty, 1, 0); if (tx == ty) { cnt[iter] += Check(iter, 0, 0, 1, 1); } if (tx == n - ty - 1) { cnt[iter] += Check(iter, n - 1, 0, -1, 1); } } if (cnt[0] >= u || cnt[1] >= v) { goto end; } } } end: if (cnt[0] >= u && cnt[1] >= v) { puts("DRAW"); } else if (cnt[0] >= u) { puts("USAGI"); } else if (cnt[1] >= v) { puts("NEKO"); } else { puts("DRAW"); } } }
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cctype> #include<math.h> #include<string> #include<string.h> #include<stack> #include<queue> #include<vector> #include<utility> #include<set> #include<map> #include<stdlib.h> #include<iomanip> using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define LINF (ll)INF*INF #define MOD 1000000007 #define rep(i,n) for(int i=0;i<(n);i++) #define loop(i,a,n) for(int i=a;i<(n);i++) #define all(in) in.begin(),in.end() #define shosu(x) fixed<<setprecision(x) #define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! typedef vector<int> vi; typedef vector<string> vs; typedef pair<int,int> pii; typedef vector<pii> vp; int gcd(int a, int b){ if(b==0) return a; return gcd(b,a%b); } int lcm(int a, int b){ return a*b/gcd(a,b); } int f(int a, int b){ a++,b++; return a*600+b; } pii g(int a){ int x = a/600; int y = a%600; x--,y--; return pii(x,y); } signed main(void) { int n,m; int num[2]; cin >> n >> num[0] >> num[1] >> m; vector<map<int,int> > ma(2); rep(i,2)rep(j,n)rep(k,n){ int in; cin >> in; ma[i][in] = f(j,k); } vi x(m); rep(i,m)cin >> x[i]; vi ans(2,INF); rep(t,2){ if(n == 1){ rep(i,m){ if(ma[t][x[i]] > 0 && num[t] == 1){ ans[t] = i; break; } } }else{ int a[500] = {}; int b[500] = {}; int c[2] = {}; int cnt = 0; rep(i,m){ if(ma[t][x[i]] == 0)continue; pii p = g(ma[t][x[i]]); int x = p.first; int y = p.second; a[x]++; if(a[x] == n)cnt++; b[y]++; if(b[y] == n)cnt++; if(x == y){ c[0]++; if(c[0] == n)cnt++; } if(x == n-1-y){ c[1]++; if(c[1] == n)cnt++; } if(cnt >= num[t]){ ans[t] = i; break; } } } } if(ans[0] < ans[1]){ cout << "USAGI" << endl; }else if(ans[0] > ans[1]){ cout << "NEKO" << endl; }else{ cout << "DRAW" << endl; } }
#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; if (n == 1) { u *= 4; v *= 4; } 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 (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 <iostream> #include <vector> #include <map> using namespace std; int n,card; void make_map(map<int,int>& col, map<int,int>& row, map<int,int>& dia, map<int,int>& rdia) { int temp; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> temp; col[temp] = j + 1; row[temp] = i + 1; if (i == j) { dia[temp] = n+1; } if (i+j == n-1) { rdia[temp] = n+2; } } } } bool check_line(int& count, map<int,int>& hash) { if (hash[card] > 0) { ++count; if (count == n) { return true; } } return false; } int main(void) { int u,v,m; cin >> n >> u >> v >> m; map<int,int> rcol,ccol; map<int,int> rrow,crow; map<int,int> rdia,cdia; map<int,int> rrdia,crdia; if (n > 1) { make_map(rcol,rrow,rdia,rrdia); make_map(ccol,crow,cdia,crdia); } else { int temp; cin >> temp; rdia[temp] = 1; cin >> temp; cdia[temp] = 1; } int rc,cc; vector<int> rc_col(n,0),cc_col(n,0); vector<int> rc_row(n,0),cc_row(n,0); vector<int> rc_dia(2,0),cc_dia(2,0); rc = cc = 0; bool fin = false; for (int i = 0; i < m; ++i) { cin >> card; if (!fin) { if (check_line(rc_col[rcol[card]-1],rcol)) { ++rc; } if (check_line(rc_row[rrow[card]-1],rrow)) { ++rc; } if (check_line(rc_dia[0],rdia)) { ++rc; } if (check_line(rc_dia[1],rrdia)) { ++rc; } if (check_line(cc_col[ccol[card]-1],ccol)) { ++cc; } if (check_line(cc_row[crow[card]-1],crow)) { ++cc; } if (check_line(cc_dia[0],cdia)) { ++cc; } if (check_line(cc_dia[1],crdia)) { ++cc; } if (rc >= u && cc >= v) { cout << "DRAW" << endl; fin = true; } else if (rc >= u) { cout << "USAGI" << endl; fin = true; } else if (cc >= v) { cout << "NEKO" << endl; fin = true; } } } if (!fin) { cout << "DRAW" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define for_(i,a,b) for(int i=(a);i<(b);++i) #define allof(a) (a).begin(),(a).end() void uniqueVector(vector< int >& vec) { sort(allof(vec)); vec.erase(unique(allof(vec)), vec.end()); } void solve( int n, int m, const vector< int >& tx, const vector< int >& ty ) { vector< int > x_sort = tx, y_sort = ty; uniqueVector(x_sort); uniqueVector(y_sort); vector< vector< int > > imos(n + 1, vector< int >(n + 1, 0)); for_(i,0,n) { int x = lower_bound(allof(x_sort), tx[i]) - x_sort.begin() + 1; int y = lower_bound(allof(y_sort), ty[i]) - y_sort.begin() + 1; ++imos[y][x]; } for_(y,0,n+1) for_(x,0,n) imos[y][x + 1] += imos[y][x]; for_(x,0,n+1) for_(y,0,n) imos[y + 1][x] += imos[y][x]; for_(i,0,m) { int lft, bot, rgt, top; scanf("%d %d %d %d", &lft, &bot, &rgt, &top); int lx = lower_bound(allof(x_sort), lft) - x_sort.begin() + 1; int by = lower_bound(allof(y_sort), bot) - y_sort.begin() + 1; int rx = upper_bound(allof(x_sort), rgt) - x_sort.begin(); int ty = upper_bound(allof(y_sort), top) - y_sort.begin(); printf("%d\n", imos[ty][rx] - imos[ty][lx - 1] - imos[by - 1][rx] + imos[by - 1][lx - 1]); } } int main() { int n, m; scanf("%d %d", &n, &m); vector< int > tx(n), ty(n); for_(i,0,n) scanf("%d %d", &tx[i], &ty[i]); solve(n, m, tx, ty); }
#include<bits/stdc++.h> #define fi first #define se second #define show(x) cerr<<#x<<"="<<x<<"\n" typedef long long ll; using namespace std; //const ll MOD=(ll)1e9+7; //const ll inf=(ll)1e14; const int dy[]={1,0,-1}; const int dx[]={1,0,-1}; int n,m,h,w; vector<int> x,y,xx,yy; int imos[5011][5011]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout<<fixed; #ifdef LOCAL_DEFINE FILE *stream1; //FILE *stream2; stream1=freopen("in","r",stdin); //stream2=freopen("out","w",stdout); if(stream1==NULL)return 0; //if(stream2==NULL)return 0; #endif cin>>n>>m; for(int i=0;i<n;i++){ int a,b;cin>>a>>b; xx.push_back(a); x.push_back(a); yy.push_back(b); y.push_back(b); } x.push_back(-1000000001); y.push_back(-1000000001); x.push_back(1000000001); y.push_back(1000000001); sort(x.begin(),x.end()); sort(y.begin(),y.end()); x.erase(unique(x.begin(),x.end()),x.end()); y.erase(unique(y.begin(),y.end()),y.end()); for(int i=0;i<n;i++){ xx[i]=lower_bound(x.begin(),x.end(),xx[i])-x.begin(); yy[i]=lower_bound(y.begin(),y.end(),yy[i])-y.begin(); } h=(int)y.size(); w=(int)x.size(); for(int i=0;i<n;i++){ imos[yy[i]][xx[i]]++; } for(int i=0;i<h;i++)for(int j=1;j<w;j++)imos[i][j]+=imos[i][j-1]; for(int i=1;i<h;i++)for(int j=0;j<w;j++)imos[i][j]+=imos[i-1][j]; for(int i=0;i<m;i++){ int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2; auto xa=lower_bound(x.begin(),x.end(),x1); if(*xa>=x1)xa--; auto xb=lower_bound(x.begin(),x.end(),x2); if(*xb>x2)xb--; auto ya=lower_bound(y.begin(),y.end(),y1); if(*ya>=y1)ya--; auto yb=lower_bound(y.begin(),y.end(),y2); if(*yb>y2)yb--; x1=xa-x.begin();x2=xb-x.begin();y1=ya-y.begin();y2=yb-y.begin(); cout<<imos[y2][x2]-imos[y2][x1]-imos[y1][x2]+imos[y1][x1]<<endl; } #ifdef LOCAL_DEFINE cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n"; fclose(stream1); //fclose(stream2); #endif return 0; }
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<n;++i) using namespace std; typedef pair<int,int> P; const int MAX_N = 5002; vector<P> tr; int data[MAX_N][MAX_N]; vector<int> X,Y; int n,m; int main() { scanf("%d%d",&n,&m); vector<int> u,v; rep(i,n){ int x,y; scanf("%d%d",&x,&y); X.push_back(x); u.push_back(x); Y.push_back(y); v.push_back(y); } sort(u.begin(),u.end()); sort(v.begin(),v.end()); u.erase(unique(u.begin(),u.end()),u.end()); v.erase(unique(v.begin(),v.end()),v.end()); rep(i,n){ X[i] = lower_bound(u.begin(),u.end(),X[i]) - u.begin(); Y[i] = lower_bound(v.begin(),v.end(),Y[i]) - v.begin(); data[X[i]][Y[i]]++; } rep(i,5001){ rep(j,5001){ data[i+1][j] += data[i][j]; } } rep(i,5001){ rep(j,5001){ data[i][j+1] += data[i][j]; } } rep(i,m){ int w,x,y,z; scanf("%d%d%d%d",&w,&x,&y,&z); w = lower_bound(u.begin(),u.end(),w) - u.begin(); x = lower_bound(v.begin(),v.end(),x) - v.begin(); y = upper_bound(u.begin(),u.end(),y) - u.begin(); z = upper_bound(v.begin(),v.end(),z) - v.begin(); printf("%d\n",((y == 0 || z == 0)?0:data[y-1][z-1]) - ((y == 0 || x == 0)?0:data[y-1][x-1]) - ((w == 0 || z == 0)?0:data[w-1][z-1]) + ((w == 0 || x == 0)?0:data[w-1][x-1])); } return 0; }
#include <algorithm> #include <numeric> #include <map> #include <vector> #include <iostream> using namespace std; int sum[5200][5200]; template <typename T,typename Func> T satisfy_min(Func P,T l ,T r,T eps){ while(r-l>eps){ T m=(l+r)/2; (P(m)?r:l)=m; } return r; } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < 5200; i++) { for (int j = 0; j < 5200; j++) { sum[i][j] = 0; } } int x[n], y[n]; vector<int> xs, ys; xs.push_back(-1100000000); ys.push_back(-1100000000); for (int i = 0; i < n; i++) { cin >> x[i]; cin >> y[i]; xs.push_back(x[i]); ys.push_back(y[i]); } xs.push_back(1100000000); ys.push_back(1100000000); sort(xs.begin(), xs.end()); sort(ys.begin(), ys.end()); xs.erase(unique(xs.begin(), xs.end()), xs.end()); ys.erase(unique(ys.begin(), ys.end()), ys.end()); for (int i = 0; i < n; i++) { int nx = lower_bound(xs.begin(), xs.end(), x[i]) -xs.begin(); int ny = lower_bound(ys.begin(), ys.end(), y[i]) -ys.begin(); sum[nx][ny]++; } for (int i = 1; i < 5200; i++) { for (int j = 1; j < 5200; j++) { sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1]; } } for (int i = 0; i < m; i++) { int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); int nx2 = upper_bound(xs.begin(), xs.end(), x2) -xs.begin(); int nx1 = lower_bound(xs.begin(), xs.end(), x1) -xs.begin(); int ny2 = upper_bound(ys.begin(), ys.end(), y2) -ys.begin(); int ny1 = lower_bound(ys.begin(), ys.end(), y1) -ys.begin(); nx2--; ny2--; ny1--; nx1--; printf("%d\n", sum[nx2][ny2]-sum[nx2][ny1]-sum[nx1][ny2]+sum[nx1][ny1]); } }
#include <iostream> #include <vector> #include <set> #include <algorithm> #include <map> #include <cstdio> using namespace std; int main() { int n, m; cin >> n >> m; set<int> X_, Y_; vector< pair<int,int> > x_y(n); int x, y; for(int i = 0; i < n; ++i){ cin >> x >> y; X_.insert(x); Y_.insert(y); x_y[i] = make_pair(x,y); } vector<int> X, Y; for(set<int>::iterator itr = X_.begin(); itr != X_.end(); ++itr) X.push_back(*itr); for(set<int>::iterator itr = Y_.begin(); itr != Y_.end(); ++itr) Y.push_back(*itr); map<int,int> M_x, M_y; for(int i = 0; i < X.size(); ++i) M_x[X[i]] = i; for(int i = 0; i < Y.size(); ++i) M_y[Y[i]] = i; int h = X.size(), w = Y.size(); vector< vector<int> > acum(h+2,vector<int>(w+2,0)); for(int i = 0; i < n; ++i){ int x = x_y[i].first, y = x_y[i].second; ++acum[M_x[x]+1][M_y[y]+1]; } for(int i = 1; i <= h+1; ++i){ for(int j = 1; j <= w+1; ++j){ acum[i][j] += acum[i][j-1]; } for(int j = 1; j <= w+1; ++j){ acum[i][j] += acum[i-1][j]; } } int x_1, x_2, y_1, y_2; for(int i = 0; i < m; ++i){ cin >> x_1 >> y_1 >> x_2 >> y_2; int x_1_ = lower_bound(X.begin(),X.end(),x_1)-X.begin(), y_1_ = lower_bound(Y.begin(),Y.end(),y_1)-Y.begin(), x_2_ = upper_bound(X.begin(),X.end(),x_2)-X.begin(), y_2_ = upper_bound(Y.begin(),Y.end(),y_2)-Y.begin(); cout << acum[x_2_][y_2_] - acum[x_2_][y_1_] - acum[x_1_][y_2_] + acum[x_1_][y_1_] << endl; } return 0; }
#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) 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; int main() { int n, m; cin >> n >> m; VI x(n), y(n); REP(i,n) cin >> x[i] >> y[i]; VI xs(x), ys(y); sort(xs.begin(),xs.end()); sort(ys.begin(),ys.end()); xs.erase(unique(xs.begin(),xs.end()), xs.end()); ys.erase(unique(ys.begin(),ys.end()), ys.end()); REP(i,n){ x[i] = find(xs.begin(),xs.end(),x[i]) - xs.begin(); y[i] = find(ys.begin(),ys.end(),y[i]) - ys.begin(); } int w = xs.size(), h = ys.size(); VVI s(w+1, VI(h+1)); REP(i,n) s[x[i]+1][y[i]+1]++; REP(i,w) REP(j,h+1) s[i+1][j] += s[i][j]; REP(j,h) REP(i,w+1) s[i][j+1] += s[i][j]; while (m--){ int x1, x2, y1, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); x1 = lower_bound(xs.begin(),xs.end(),x1) - xs.begin(); x2 = upper_bound(xs.begin(),xs.end(),x2) - xs.begin(); y1 = lower_bound(ys.begin(),ys.end(),y1) - ys.begin(); y2 = upper_bound(ys.begin(),ys.end(),y2) - ys.begin(); int ans = s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1]; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int A[5010][2]; short S[10005][10005]; int ANS = 0; int *R; int Xs[10005], Ys[10005]; map<int,int> zipx, zipy; int MAX = 1000000001; int compress(int *X, map<int, int> &zip, int n) { sort(X, X + n); R = unique(X, X + n); int k = R - X; for(int i = 0; i < k; i++){ zip[X[i]] = i; } return k; } int main(){ int N, M, x1, y1, x2, y2, xn, yn, ans; cin >> N >> M; for (int n = 0; n < N; n++) { cin >> x1 >> y1; A[n][0] = x1; A[n][1] = y1; Xs[n * 2] = x1; Xs[n * 2 + 1] = x1 - 1; Ys[n * 2] = y1; Ys[n * 2 + 1] = y1 - 1; } Xs[N * 2] = -1 * MAX; Xs[N * 2 + 1] = MAX; Ys[N * 2] = -1 * MAX; Ys[N * 2 + 1] = MAX; xn = compress(Xs, zipx, N * 2 + 2); yn = compress(Ys, zipy, N * 2 + 2); for (int n = 0; n < N; n ++) { x1 = zipx[A[n][0]]; y1 = zipy[A[n][1]]; S[x1][y1] ++; } for (int x = 1; x <= xn; x++) { for (int y = 1; y <= yn; y ++) { S[x][y] += S[x - 1][y] + S[x][y - 1] - S[x - 1][y - 1]; } } for (int m = 0; m < M; m ++) { cin >> x1 >> y1 >> x2 >> y2; x1 = *lower_bound(Xs, Xs + xn, x1 - 1); y1 = *lower_bound(Ys, Ys + yn, y1 - 1); x2 = *lower_bound(Xs, Xs + xn, x2); y2 = *lower_bound(Ys, Ys + yn, y2); x1 = zipx[x1]; x2 = zipx[x2]; y1 = zipy[y1]; y2 = zipy[y2]; ans = S[x2][y2] - S[x1][y2] - S[x2][y1] + S[x1][y1]; cout << ans << endl; } }
#include<cstdio> #include<vector> #include<algorithm> using namespace std; void compress(vector<int> &c){ sort(c.begin(),c.end()); c.erase(unique(c.begin(),c.end()),c.end()); } int idx(int i,vector<int> &c){ return lower_bound(c.begin(),c.end(),i)-c.begin(); } int sum[5010][5010]; int main(){ int xs[5000],ys[5000]; int n,m; scanf("%d%d",&n,&m); vector<int>x(n),y(n); for(int i=0;i<n;i++){ scanf("%d%d",xs+i,ys+i); x[i]=xs[i]; y[i]=ys[i]; } compress(x);compress(y); for(int i=0;i<n;i++){ int fx=idx(xs[i],x); int fy=idx(ys[i],y); sum[fy+1][fx+1]++; } for(int i=0;i<y.size();i++){ for(int j=0;j<x.size();j++){ sum[i+1][j+1]+=sum[i][j+1]+sum[i+1][j]-sum[i][j]; } } for(int i=0;i<m;i++){ int x1,x2,y1,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); x1=idx(x1,x); y1=idx(y1,y); x2=idx(x2+1,x); y2=idx(y2+1,y); printf("%d\n",sum[y2][x2]-sum[y2][x1]-sum[y1][x2]+sum[y1][x1]); } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const int MAXN = 5000; const int B = 250; const int BNUM = MAXN / B; int n, m; pair<int, int> ps[MAXN]; int x[MAXN], y[MAXN]; vector<int> bucket[BNUM]; int main() { while(scanf("%d%d", &n, &m) != EOF) { for(int i = 0; i < n; ++i) { scanf("%d%d", &ps[i].first, &ps[i].second); } sort(ps, ps+n); fill(bucket, bucket + BNUM, vector<int>()); for(int i = 0; i < n; ++i) { x[i] = ps[i].first; y[i] = ps[i].second; bucket[i/B].push_back(y[i]); } for(int b = 0; b < BNUM; ++b) { sort(bucket[b].begin(), bucket[b].end()); } while(m--) { int s, t, u, v; scanf("%d%d%d%d", &s, &t, &u, &v); int l = lower_bound(x, x+n, s) - x; int r = upper_bound(x, x+n, u) - x; int res = 0; while(l < r && l % B != 0) { res += (t <= y[l] && y[l] <= v); ++l; } while(l < r && r % B != 0) { --r; res += (t <= y[r] && y[r] <= v); } while(l < r) { int b = l / B; res += upper_bound(bucket[b].begin(), bucket[b].end(), v) - lower_bound(bucket[b].begin(), bucket[b].end(), t); l += B; } printf("%d\n", res); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); i++) #define repp(i, l, r) for(int i = (l); i < (r); i++) #define per(i, n) for(int i = ((n)-1); i >= 0; i--) #define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(),(x).end() #define MOD 1000000007 #define IINF 1000000100 #define LINF 1000000000000000000 #define SP <<" "<< #define CYES cout<<"Yes"<<endl #define CNO cout<<"No"<<endl #define CFS cin.tie(0);ios::sync_with_stdio(false) typedef long long LL; typedef long double LD; int main(){ int n,m; cin >> n >> m; vector<pair<int,int>> tre(n); map<int,int> xmp,ymp; rep(i,n){ cin >> tre[i].first >> tre[i].second; xmp[tre[i].first]=-1; ymp[tre[i].second]=-1; } xmp[IINF]=-1; ymp[IINF]=-1; int xsz=0; for(auto &p:xmp) p.second=(xsz++); int ysz=0; for(auto &p:ymp) p.second=(ysz++); vector<vector<int>> rui(xsz+1,vector<int>(ysz+1,0)); rep(i,n){ rui[xmp[tre[i].first]+1][ymp[tre[i].second]+1]++; } repp(i,1,xsz+1){ repp(j,1,ysz+1){ rui[i][j]+=rui[i-1][j]+rui[i][j-1]-rui[i-1][j-1]; } } int x1,y1,x2,y2; rep(i,m){ cin >> x1 >> y1 >> x2 >> y2; x1=xmp.lower_bound(x1)->second; y1=ymp.lower_bound(y1)->second; x2=xmp.upper_bound(x2)->second; y2=ymp.upper_bound(y2)->second; cout << rui[x2][y2]-rui[x1][y2]-rui[x2][y1]+rui[x1][y1] << endl; } return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <cstdio> #include <climits> using namespace std; vector<int> x,y; vector<int> ux,uy; short data[5002][5002]; int main(){ int n,m; cin >> n >> m; for(int i = 0 ; i < n ; i++){ int a,b; cin >> a >> b; x.push_back(a); y.push_back(b); } ux = x; uy = y; ux.push_back(INT_MAX); ux.push_back(INT_MIN); uy.push_back(INT_MAX); uy.push_back(INT_MIN); sort(ux.begin(),ux.end()); sort(uy.begin(),uy.end()); ux.erase(unique(ux.begin(),ux.end()),ux.end()); uy.erase(unique(uy.begin(),uy.end()),uy.end()); for(int i = 0 ; i < x.size() ; i++){ x[i] = lower_bound(ux.begin(),ux.end(),x[i]) - ux.begin(); y[i] = lower_bound(uy.begin(),uy.end(),y[i]) - uy.begin(); data[y[i]][x[i]]++; } for(int i = 0 ; i < 5002 ; i++) for(int j = 1 ; j < 5002 ; j++) data[i][j] += data[i][j-1]; for(int i = 1 ; i < 5002 ; i++) for(int j = 0 ; j < 5002 ; j++) data[i][j] += data[i-1][j]; for(int i = 0 ; i < m ; i++){ int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d); a = lower_bound(ux.begin(),ux.end(),a) - ux.begin(); b = lower_bound(uy.begin(),uy.end(),b) - uy.begin(); c = upper_bound(ux.begin(),ux.end(),c) - ux.begin() - 1; d = upper_bound(uy.begin(),uy.end(),d) - uy.begin() - 1; //cout << a << " " << b << " " << c << " " << d << endl; int answer = data[d][c] - data[d][a-1] - data[b-1][c] + data[b-1][a-1]; printf("%d%c",answer,10); } }
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <cstring> #include <string> #include <cstdlib> #include <cstdio> using namespace std; typedef long long int ll; typedef vector<pair<int, int> > vpii; int n, m; int main(){ int i,j; while(cin >> n >> m){ int ans; vpii data(n); for(i=0;i<n;i++) cin >> data[i].first >> data[i].second; sort(data.begin(), data.end()); for(i=0;i<m;i++){ int x1,y1,x2,y2,ans=0; cin >> x1 >> y1 >> x2 >> y2; vpii::iterator itr1 = lower_bound(data.begin(), data.end(), pair<int, int>(x1, y1)); vpii::iterator itr2 = upper_bound(data.begin(), data.end(), pair<int, int>(x2, y2)); for(;itr1!=itr2;++itr1){ if(y1 <= (*itr1).second && (*itr1).second <= y2) ans ++; } cout << ans << endl; } } return 0; }