結果
| 問題 |
No.2719 Equal Inner Products in Permutation
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2024-04-06 10:36:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 57 ms / 2,000 ms |
| コード長 | 2,610 bytes |
| コンパイル時間 | 4,314 ms |
| コンパイル使用メモリ | 254,660 KB |
| 最終ジャッジ日時 | 2025-02-20 22:30:46 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/
/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/
typedef long long ll;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
template <typename T> bool chmin(T &a, const T &b) {
if (a <= b) return false;
a = b;
return true;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a >= b) return false;
a = b;
return true;
}
template <typename T> T max(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
return ret;
}
template <typename T> T min(vector<T> &a){
assert(!a.empty());
T ret = a[0];
for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
return ret;
}
template <typename T> T sum(vector<T> &a){
T ret = 0;
for (int i=0; i<(int)a.size(); i++) ret += a[i];
return ret;
}
void validation(int n, vector<int> p){
assert(p.size() == 3 * n);
vector<int> dar(3 * n);
rep(i,0,3 * n){
assert(1 <= p[i] && p[i] <= 3 * n);
assert(dar[p[i] - 1] == 0);
dar[p[i] - 1] = 1;
}
ll t = 0;
rep(i,0,n){
t += p[i] * p[i+n];
t -= p[i+n] * p[i+2*n];
}
assert(t == 0);
}
int main(){
int n; cin >> n;
vector<vector<int>> small = {
{-1},
{-1},
{1, 4, 3, 6, 5, 2},
{2, 9, 1, 6, 7, 8, 5, 3, 4},
{7, 10, 2, 8, 1, 3, 11, 9, 6, 12, 4, 5},
};
if (n <= 4){
int m = small[n].size();
//validation(n, small[n]);
rep(i,0,m){
cout << small[n][i] << ' ';
}
cout << '\n';
}else{
vector<int> base;
if (n % 3 == 0){
base = small[3];
}else if(n % 3 == 1){
base = small[4];
}else if(n % 3 == 2){
base = small[2];
}
vector<int> up;
vector<int> middle;
vector<int> down;
rep(i,0,(int)base.size() / 3){
up.push_back(base[i]);
}
rep(i,(int)base.size() / 3, (int)base.size() / 3 * 2){
middle.push_back(base[i]);
}
rep(i,(int)base.size() / 3 * 2, (int)base.size() / 3 * 3){
down.push_back(base[i]);
}
while((int)up.size() < n){
int k = (int)up.size() * 3;
rep(i,0,3){
up.push_back(small[3][i] + k);
}
rep(i,3,6){
middle.push_back(small[3][i] + k);
}
rep(i,6,9){
down.push_back(small[3][i] + k);
}
}
vector<int> ans;
for (int i: up) ans.push_back(i);
for (int i: middle) ans.push_back(i);
for (int i: down) ans.push_back(i);
int m = ans.size();
//validation(n, ans);
rep(i,0,m){
cout << ans[i] << ' ';
}
cout << '\n';
}
}
shobonvip