結果
問題 | No.452 横着者のビンゴゲーム |
ユーザー |
|
提出日時 | 2016-12-03 00:45:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 282 ms / 3,000 ms |
コード長 | 2,220 bytes |
コンパイル時間 | 1,990 ms |
コンパイル使用メモリ | 182,876 KB |
実行使用メモリ | 9,692 KB |
最終ジャッジ日時 | 2024-11-28 21:22:34 |
合計ジャッジ時間 | 5,203 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<<endl #define smax(x,y) (x)=max((x),(y)) #define smin(x,y) (x)=min((x),(y)) #define MEM(x,y) memset((x),(y),sizeof (x)) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef tuple<int, int, int> tp; tp f(int x, int y, int z) { static int uuu[3]; uuu[0] = x; uuu[1] = y; uuu[z] = z; sort(uuu, uuu + 3); return mt(uuu[0], uuu[1], uuu[2]); } int N, M; int C[200][100][100]; vector<vi> vv, ww; int same(vi &u, vi &v) { int i = 0, j = 0, res = 0; while(i < N&&j < N) { if(u[i] < v[j])i++; else if(u[i] > v[j])j++; else { i++; j++; res++; } } return res; } void g() { ww.clear(); vv.clear(); vi v; int ans = INT_MAX; rep(i, M) { vv.clear(); // 横 rep(y, N) { v.clear(); rep(x, N)v.push_back(C[i][y][x]); vv.push_back(v); } // 縦 rep(x, N) { v.clear(); rep(y, N)v.push_back(C[i][y][x]); vv.push_back(v); } // 斜め1:左上から右下 { v.clear(); rep(j, N) v.push_back(C[i][j][j]); vv.push_back(v); } // 斜め2:右上から左下 { v.clear(); for(int y = 0, x = N - 1; y < N; ++y, --x) { v.push_back(C[i][y][x]); } vv.push_back(v); } each(u, vv) { sort(all(u)); each(w, ww) { int cnt = same(u, w); smin(ans, 2 * N - cnt - 1); } } each(u, vv)ww.push_back(u); } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); while(cin >> N >> M) { rep(i, M)rep(j, N)rep(k, N)cin >> C[i][j][k]; g(); } }