結果
| 問題 |
No.1630 Sorting Integers (Greater than K)
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-07-30 21:11:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,188 bytes |
| コンパイル時間 | 1,395 ms |
| コンパイル使用メモリ | 117,504 KB |
| 最終ジャッジ日時 | 2025-01-23 10:58:10 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 2 |
| other | AC * 8 WA * 14 |
コンパイルメッセージ
main.cpp: In function ‘bool dfs(int, bool)’:
main.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
71 | }
| ^
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
int n, m;
vector<int> c(10);
vector<int> v;
vector<int> get_input(){
string s; cin >> s;
int n = s.size();
vector<int> ans(n);
vector<int> v(n);
for(int i = 0; i < n; i++) {
char c = s[i];
v[i] = c-'0';
}
int carry = 1;
for(int i = n-1; i >= 0; i--){
ans[i] = v[i]+carry;
if(ans[i] == 10){
ans[i] = 0;
carry = 1;
}else{
carry = 0;
}
}
if(carry == 1){
vector<int> u(n+1);
u[0] = 1;
for(int i = 1; i <= n; i++) u[i] = ans[i-1];
return u;
}
return ans;
}
string ans;
bool dfs(int i, bool big){
// debug_value(i)
if(i == m){
cout << ans << endl;
return true;
}
for(int j = 1; j <= 9; j++){
if(!big && j < v[i]) continue;
if(c[j] > 0){
c[j]--;
ans += j+'0';
if(dfs(i+1, big || j > v[i])) return true;
ans.pop_back();
c[j]++;
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> n;
v = get_input();
for(int i = 1; i <= 9; i++) cin >> c[i];
int k = accumulate(c.begin(), c.end(), 0);
string ans;
m = v.size();
if(k < m){
cout << -1 << endl;
return 0;
}
if(k > m){
for(int i = 9; i >= 1; i--){
for(int j = 0; j < c[i]; j++) cout << i;
}
cout << endl;
return 0;
}
if(!dfs(0, false)) cout << -1 << endl;
}
milanis48663220