結果
問題 | No.223 1マス指定の魔方陣 |
ユーザー | fumiphys |
提出日時 | 2019-10-07 01:44:19 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 5,092 bytes |
コンパイル時間 | 2,007 ms |
コンパイル使用メモリ | 166,848 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 23:15:11 |
合計ジャッジ時間 | 3,364 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | AC | 2 ms
5,248 KB |
testcase_31 | AC | 2 ms
5,248 KB |
testcase_32 | AC | 2 ms
5,248 KB |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | AC | 2 ms
5,248 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 2 ms
5,248 KB |
testcase_37 | AC | 2 ms
5,248 KB |
testcase_38 | AC | 2 ms
5,248 KB |
testcase_39 | AC | 2 ms
5,248 KB |
testcase_40 | AC | 2 ms
5,248 KB |
testcase_41 | AC | 2 ms
5,248 KB |
testcase_42 | AC | 2 ms
5,248 KB |
testcase_43 | AC | 2 ms
5,248 KB |
testcase_44 | AC | 2 ms
5,248 KB |
testcase_45 | AC | 2 ms
5,248 KB |
testcase_46 | AC | 2 ms
5,248 KB |
ソースコード
// includes #include <bits/stdc++.h> using namespace std; // macros #define pb emplace_back #define mk make_pair #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--) #define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr) #define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr) #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define bit(n) (1LL<<(n)) // functions template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;} template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;} template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;} template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} // types using ll = long long int; using P = pair<int, int>; // constants const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1000000007; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; // io struct fast_io{ fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);} } fast_io_; int f[16][16] = { {6,12,7,9}, {15,1,14,4}, {10,8,11,5}, {3,13,2,16} }; int e[16][16] = { {1,32,45,52,49,48,29,4}, {54,43,26,7,6,27,42,55}, {60,37,24,9,12,21,40,57}, {15,18,35,62,63,34,19,14}, {13,20,33,64,61,36,17,16}, {58,39,22,11,10,23,38,59}, {56,41,28,5,8,25,44,53}, {3,30,47,50,51,46,31,2}, }; int s[16][16] = { {1,240,49,224,5,236,53,220,9,232,57,216,13,228,61,212}, {255,18,207,34,251,22,203,38,247,26,199,42,243,30,195,46}, {4,237,52,221,8,233,56,217,12,229,60,213,16,225,64,209}, {254,19,206,35,250,23,202,39,246,27,198,43,242,31,194,47}, {65,176,113,160,69,172,117,156,73,168,121,152,77,164,125,148}, {191,82,143,98,187,86,139,102,183,90,135,106,179,94,131,110}, {68,173,116,157,72,169,120,153,76,165,124,149,80,161,128,145}, {190,83,142,99,186,87,138,103,182,91,134,107,178,95,130,111}, {129,112,177,96,133,108,181,92,137,104,185,88,141,100,189,84}, {127,146,79,162,123,150,75,166,119,154,71,170,115,158,67,174}, {132,109,180,93,136,105,184,89,140,101,188,85,144,97,192,81}, {126,147,78,163,122,151,74,167,118,155,70,171,114,159,66,175}, {193,48,241,32,197,44,245,28,201,40,249,24,205,36,253,20}, {63,210,15,226,59,214,11,230,55,218,7,234,51,222,3,238}, {196,45,244,29,200,41,248,25,204,37,252,21,208,33,256,17}, {62,211,14,227,58,215,10,231,54,219,6,235,50,223,2,239}, }; int ans[16][16]; int main(int argc, char const* argv[]) { int n, x, y, z; cin >> n >> y >> x >> z; x--; y--; auto g = f; if(n == 8)g = e; else if(n == 16)g = s; int X = 0, Y = 0; rep(i, n)rep(j, n){ if(g[i][j] == z){ X = i; Y = j; } } int ddx = X - x; int ddy = Y - y; rep(i, n)rep(j, n){ ans[i][j] = g[(i+ddx+n)%n][(j+ddy+n)%n]; } rep(i, n)rep(j, n){ cout << ans[i][j] << "\n "[j + 1 != n]; } return 0; }