結果
問題 | No.927 Second Permutation |
ユーザー |
|
提出日時 | 2019-11-22 22:53:47 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 1,383 bytes |
コンパイル時間 | 2,205 ms |
コンパイル使用メモリ | 162,864 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-11 04:31:53 |
合計ジャッジ時間 | 2,484 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for(int i=0; i<(n); ++i)#define rep1(i,n) for(int i=1; i<=(n); ++i)#define repi(i,a,b) for(int i=a; i<=(b); ++i)#define rrep(i,n) for(int i=(n-1); i>=0; --i)#define ALL(obj) (obj).begin(), (obj).end()#define RALL(obj) (obj).rbegin(), (obj).rend()#define pb push_back#define mp make_pair#define to_s to_string#define sz(v) (int)v.size()#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )#define pr(x) cout<<(x)<<'\n'#define debug(x) cout << #x << ": " << (x) << '\n'#define yes "Yes"#define no "No"using namespace std;using ll = long long;using Edge = pair<int,long long>;using Graph = vector<vector<Edge>>;typedef pair<int,int> P;struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;int MOD = 1e9 + 7;ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}int dx[4]={1,0,-1,0};int dy[4]={0,1,0,-1};string solve(string X){sort(ALL(X));reverse(ALL(X));string ans = X;ll i = sz(X)-2;while(i >= 0){if(ans[i+1]!=ans[i]){char tp = ans[i];ans[i] = ans[i+1];ans[i+1] = tp;break;}i--;}if(ans[0] == '0' || ans == X) return "-1";else return ans;}int main(){string X; cin >> X;pr(solve(X));return 0;}