結果

問題 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
コンパイル時間 857 ms
コンパイル使用メモリ 89,020 KB
実行使用メモリ 4,736 KB
最終ジャッジ日時 2023-09-19 08:15:21
合計ジャッジ時間 5,235 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 91 ms
4,612 KB
testcase_16 AC 89 ms
4,664 KB
testcase_17 AC 77 ms
4,620 KB
testcase_18 AC 76 ms
4,736 KB
testcase_19 AC 77 ms
4,544 KB
testcase_20 AC 87 ms
4,588 KB
testcase_21 AC 85 ms
4,684 KB
testcase_22 AC 76 ms
4,612 KB
testcase_23 AC 85 ms
4,736 KB
testcase_24 AC 85 ms
4,684 KB
testcase_25 AC 8 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 11 ms
4,380 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 8 ms
4,380 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 8 ms
4,380 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 39 ms
4,380 KB
testcase_36 AC 39 ms
4,376 KB
testcase_37 AC 57 ms
4,676 KB
testcase_38 AC 79 ms
4,608 KB
testcase_39 AC 59 ms
4,544 KB
testcase_40 AC 75 ms
4,564 KB
testcase_41 AC 77 ms
4,588 KB
testcase_42 WA -
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 WA -
testcase_48 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/string:47,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/locale_classes.h:40,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/ios_base.h:41,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ios:42,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ostream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/iostream:39,
         次から読み込み:  main.cpp:1:
メンバ関数 ‘__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:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_iterator.h:1144:47: 警告: ‘qi’ may be used uninitialized [-Wmaybe-uninitialized]
 1144 |       { return __normal_iterator(_M_current + __n); }
      |                                               ^~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:63:15: 備考: ‘qi’ はここで定義されています
   63 |         ll pi,qi;
      |               ^~
main.cpp:68:9: 警告: ‘pi’ may be used uninitialized [-Wmaybe-uninitialized]
   68 |         if(pi < qi){
      |         ^~
main.cpp:63:12: 備考: ‘pi’ はここで定義されています
   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