結果
問題 |
No.927 Second Permutation
|
ユーザー |
![]() |
提出日時 | 2020-02-24 17:58:22 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 485 bytes |
コンパイル時間 | 1,629 ms |
コンパイル使用メモリ | 169,380 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-12 06:24:04 |
合計ジャッジ時間 | 2,926 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using longlong=long long; int main(){ std::cin.tie(nullptr);std::cin.sync_with_stdio(false); std::string s;std::cin>>s; std::vector<int>a(10); for(char c:s)a.at(c-'0')++; std::string t; for(int i=9;i>=0;i--){ while(a.at(i)--){ t.push_back('0'+i); } } if(!std::prev_permutation(t.begin(),t.end())||t.front()=='0'){ std::cout<<-1<<std::endl; }else{ std::cout<<t<<std::endl; } }