結果
問題 | No.2719 Equal Inner Products in Permutation |
ユーザー |
👑 |
提出日時 | 2024-04-06 05:23:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 2,283 bytes |
コンパイル時間 | 4,459 ms |
コンパイル使用メモリ | 256,552 KB |
最終ジャッジ日時 | 2025-02-20 22:25:35 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h>#include<atcoder/all>#define rep(i,n) for(int i=0;i<n;i++)using namespace std;using namespace atcoder;typedef long long ll;typedef vector<int> vi;typedef vector<long long> vl;typedef vector<vector<int>> vvi;typedef vector<vector<long long>> vvl;typedef long double ld;typedef pair<int, int> P;ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); returnos;}template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : "");return os;}template<typename T> void chmin(T& a, T b){a = min(a, b);}template<typename T> void chmax(T& a, T b){a = max(a, b);}int main(){vector<vector<int>> ans2 = {{1, 4}, {3, 6}, {5, 2}};vector<vector<int>> ans3 = {{1, 2, 9}, {6, 8, 7}, {3, 4, 5}};vector<vector<int>> ans4 = {{1, 2, 5, 12}, {8, 10, 11, 9}, {3, 6, 4, 7}};int n;cin >> n;if(n == 1){cout << "-1\n";return 0;}int shift = 0;vector<vector<int>> ans;if(n % 3 == 2){ans = ans2;n -= 2;shift = 6;}else if(n % 3 == 0){ans = ans3;n -= 3;shift = 9;}else if(n % 3 == 1){ans = ans4;n -= 4;shift = 12;}while(n >= 3){rep(i, 3){rep(j, 3) ans[i].push_back(ans3[i][j] + shift);}shift += 9;n -= 3;}auto judge = [&]{long long prod = 0;int n = ans[0].size();rep(i, n) prod += ans[0][i] * ans[1][i];rep(i, n) prod -= ans[1][i] * ans[2][i];if(prod == 0) return true;else return false;};// if(judge()) cout << "OK\n";// else cout << "NG\n";vector<int> res;rep(i, 3){for(int x : ans[i]) res.push_back(x);}cout << res;return 0;}