結果

問題 No.927 Second Permutation
ユーザー yicode
提出日時 2023-06-12 13:14:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 553 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 171,556 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-11 15:32:14
合計ジャッジ時間 3,213 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
int main() {
  string S; cin >> S;
  sort(S.begin(),S.end());
  reverse(S.begin(),S.end());
  
  int count = 0;
  for(int i = 0; i < S.size(); i++) {
    if(S[0] == S[i]) {
      count++;
    }
  }
  int zero = 0;
  for(int i = 1;i < S.size(); i++) {
    if('0' == S[i]) {
      zero++;
    }
  }
  swap(S[S.size()-1],S[S.size() - 2]);
  if(count == S.size() || zero == S.size() - 1) {
    cout << -1 << endl;
    return 0;
  }
  cout << S << endl;
}
0