結果

問題 No.1051 PQ Permutation
ユーザー suta28407928suta28407928
提出日時 2020-05-09 01:07:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,357 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 95,632 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 20:08:19
合計ジャッジ時間 4,361 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 84 ms
5,376 KB
testcase_16 AC 81 ms
5,376 KB
testcase_17 AC 73 ms
5,376 KB
testcase_18 AC 71 ms
5,376 KB
testcase_19 AC 69 ms
5,376 KB
testcase_20 AC 77 ms
5,376 KB
testcase_21 AC 77 ms
5,376 KB
testcase_22 AC 69 ms
5,376 KB
testcase_23 AC 80 ms
5,376 KB
testcase_24 AC 76 ms
5,376 KB
testcase_25 AC 7 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 10 ms
5,376 KB
testcase_29 AC 5 ms
5,376 KB
testcase_30 AC 7 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 8 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 34 ms
5,376 KB
testcase_36 AC 35 ms
5,376 KB
testcase_37 AC 51 ms
5,376 KB
testcase_38 AC 75 ms
5,376 KB
testcase_39 AC 53 ms
5,376 KB
testcase_40 AC 70 ms
5,376 KB
testcase_41 AC 70 ms
5,376 KB
testcase_42 WA -
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 WA -
testcase_48 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:47,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39,
                 from main.cpp:1:
In member function '__gnu_cxx::__normal_iterator<_Iterator, _Container> __gnu_cxx::__normal_iterator<_Iterator, _Container>::operator+(difference_type) const [with _Iterator = long long int*; _Container = std::vector<long long int>]',
    inlined from 'int main()' at main.cpp:72:24:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_iterator.h:1144:47: warning: 'qi' may be used uninitialized [-Wmaybe-uninitialized]
 1144 |       { return __normal_iterator(_M_current + __n); }
      |                                               ^~~
main.cpp: In function 'int main()':
main.cpp:63:15: note: 'qi' was declared here
   63 |         ll pi,qi;
      |               ^~
main.cpp:68:9: warning: 'pi' may be used uninitialized [-Wmaybe-uninitialized]
   68 |         if(pi < qi){
      |         ^~
main.cpp:63:12: note: 'pi' was declared here
   63 |         ll pi,qi;
      |            ^~

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n,p,q; cin >> n >> p >> q;
    vl a(n); rep(i,n) cin >> a[i];
    if(next_permutation(all(a))){
        ll pi,qi;
        rep(i,n){
            if(a[i]==p) pi = i;
            if(a[i]==q) qi = i;
        }
        if(pi < qi){
            print(a);
            return 0;
        }
        sort(a.begin()+qi+1,a.end());
        reverse(a.begin()+qi+1,a.end());
        if(!next_permutation(all(a))){
            puts("-1");
            return 0;
        }
        rep(i,n){
            if(a[i]==p) pi = i;
            if(a[i]==q) qi = i;
        }
        if(pi < qi){
            print(a);
            return 0;
        }
        bool flag = false;
        rep(i,n){
            if(a[i]==q) flag = true;
            if(flag) swap(a[i],a[i+1]);
            if(a[i]==p) break;
        }
        print(a);
    }else{
        puts("-1");
    }
}
0