結果
問題 | No.1051 PQ Permutation |
ユーザー | suta28407928 |
提出日時 | 2020-05-09 01:07:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 WA * 3 |
コンパイルメッセージ
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; | ^~
ソースコード
#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");}}