結果
| 問題 |
No.1630 Sorting Integers (Greater than K)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-30 22:13:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,303 bytes |
| コンパイル時間 | 886 ms |
| コンパイル使用メモリ | 95,308 KB |
| 実行使用メモリ | 10,676 KB |
| 最終ジャッジ日時 | 2024-09-16 00:34:49 |
| 合計ジャッジ時間 | 7,446 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 3 WA * 18 TLE * 1 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long c[10];
int main() {
long long n;
string s;
cin >> n >> s;
long long ans = 0;
long long sum = 0, p = 1;
for (int i = 1; i <= 9; i++) {
cin >> c[i];
}
if (s.size() < n) {
for (int i = 1; i <= 9; i++) {
for (int j = 0; j < c[i]; j++) {
cout << i;
}
}
cout << endl;
}
else if (s.size() > n) {
cout << -1 << endl;
}
else {
string ans1 = "";
for (int i = 9; i >= 1; i--) {
for (int j = 0; j < c[i]; j++) {
ans1 += char(i + '0');
}
}
if (s >= ans1) {
cout << -1 << endl;
}
else {
string ans = ans1;
reverse(ans1.begin(), ans1.end());
for (int i = 0; i < n; i++) {
auto itr = lower_bound(ans1.begin() + i + 1, ans1.end(), s[i]);
if (itr == ans1.end() || *itr > s[i]) {
break;
}
else {
swap(ans1[i], *itr);
ans = ans1;
}
}
if (ans == s) {
for (int i = n - 1; i > 0; i--) {
if (ans[i] != ans[i - 1]) {
swap(ans[i], ans[i - 1]);
break;
}
}
}
cout << ans << endl;
}
}
}