結果

問題 No.927 Second Permutation
コンテスト
ユーザー lumc_
提出日時 2019-11-22 23:19:11
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 2,000 ms
+ 612µs
コード長 763 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 603 ms
コンパイル使用メモリ 121,324 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-10-12 04:38:32
合計ジャッジ時間 2,131 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  string s;
  cin >> s;
  sort(rbegin(s), rend(s));
  if(s[0] == s.back()) return cout << -1 << endl, 0;
  for(int i = s.size() - 1; i >= 1; i--) {
    if(s[i] != s[i-1]) {
      swap(s[i], s[i-1]);
      break;
    }
  }
  if(s[0] == '0') return cout << -1 << endl, 0;
  cout << s << endl;
  return 0;
}
0