結果

問題 No.927 Second Permutation
ユーザー yujirosan
提出日時 2019-11-22 22:18:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 756 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 171,732 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 03:59:55
合計ジャッジ時間 2,763 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
typedef long long ll;
#define rALL(a) (a).rbegin(),(a).rend()



int main(){
  ll x; cin >> x;
  vector<int> a;
  while(x!=0){
    a.push_back(x%10);
    x = x/10;
  }
  sort(a.begin(),a.end(),greater<int>());
  bool flag = true;
  if(a[0]!=0 && a[1]==0) flag = false;
  for(int i=1;i<a.size()-1;i++){
    if(a[i]!=a[i+1]){
      int tmp=a[i];
      a[i] = a[i+1];
      a[i+1] = tmp;
      break;
    }
    if(i==a.size()-2) flag = false;
  }
  if(a[0] == 0) false;
  
  ll ans=0;
  if(flag){
    rep(i,a.size()){
      ans = ans*10 + a[i];
    }
  }
  
  if(flag) cout << ans << endl;
  else cout << -1 << endl;
  
  return 0;
}

0