結果

問題 No.2289 順列ソート
ユーザー Ramurata
提出日時 2023-05-05 22:32:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,983 bytes
コンパイル時間 3,733 ms
コンパイル使用メモリ 252,852 KB
最終ジャッジ日時 2025-02-12 18:49:15
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#line 2 "/Users/2P/Desktop/ramstream/library/template/template.hpp"
/**
* @brief Header
*/
#include <bits/stdc++.h>
// #include <algorithm>
// #include <cmath>
// #include <complex>
// #include <cstdio>
// #include <iostream>
// #include <map>
// #include <numeric>
// #include <queue>
// #include <set>
// #include <stack>
// #include <string>
// #include <vector>
// #include <climits>
// #include <deque>
// #include <iomanip>
// #include <limits>
using namespace std;
typedef long long ll;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(i, n) for (int i = 0; i < int(n); ++i)
#define rep2(i, s, n) for (int i = int(s); i < int(n); ++i)
#define rep3(i, s, n, d) for(int i = int(s); i < int(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fir first
#define sec second
#define pb push_back
#define em emplace_back
#define mk make_pair
#define SUM(a) accumulate(all(a),0LL)
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
template<class... T> void input(T&... a){(cin >> ... >> a);}
#define INT(...) int __VA_ARGS__;input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;input(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;input(__VA_ARGS__)
void Yes(bool iSizIs=true) {if(iSizIs){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void No() {cout<<"No"<<endl;}
template<class T> void OUT(T x) {cout << (x) << endl;}
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;}
ll POW(ll a, ll n, ll MOD) {
if (n == 0) return 1;
if (n == 1) return a % MOD;
ll ret = POW(a, n / 2, MOD) % MOD;
(ret *= ret) %= MOD;
if (n % 2 == 1) {
(ret *= a) %= MOD;
}
return ret;
}
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
#include <atcoder/all>
using namespace atcoder;
#line 2 "sol.cpp"
int main() {
int n; cin >> n;
vi a(n+1);
vi p(n+1);
rep(i,1,n+1) cin >> a[i], p[a[i]] = i;
vi aa = a, pp = p;
int ans = 0;
rep(i,1,n+1) {
if(p[i] == i) continue;
int x = p[i];
a[p[i]] = a[i];
p[i] = i;
p[x] = a[i];
a[i] = i;
ans++;
}
int ans2 = 0;
a = aa, p = pp;
for(int i = n; i >= 1; i--) {
if(p[i] == i) continue;
int x = p[i];
a[p[i]] = a[i];
p[i] = i;
p[x] = a[i];
a[i] = i;
ans2++;
}
cout << min(ans, ans2) << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0