結果
問題 |
No.927 Second Permutation
|
ユーザー |
|
提出日時 | 2020-03-29 18:46:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 775 bytes |
コンパイル時間 | 1,756 ms |
コンパイル使用メモリ | 166,604 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-02 15:40:23 |
合計ジャッジ時間 | 2,870 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:33:18: warning: ‘ss’ may be used uninitialized [-Wmaybe-uninitialized] 33 | swap(s[ss+1],s[ss]); | ~~^~ main.cpp:25:9: note: ‘ss’ was declared here 25 | int ss; | ^~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i<(n); ++i) using namespace std; using ll=long long; int main(){ string s; cin>>s; sort(s.rbegin(),s.rend()); bool zero=false; int cnt=0; for(int i=1; i<s.length(); ++i){ if(s[i]=='0')cnt++; if(s.length()-1==cnt)zero=true; } cnt=0; rep(i,s.length()){ if(s[i]==s[0])cnt++; if(s.length()==cnt)zero=true; } if(zero==true){ cout<<-1<<endl; return 0; } int ss; if(zero==false){ for(int i=s.length()-2; i>=0; --i){ if(s[i]!='0'){ ss=i; break; } } swap(s[ss+1],s[ss]); rep(i,s.length()){ cout<<s[i]; } } }