結果
| 問題 |
No.1630 Sorting Integers (Greater than K)
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2023-05-04 14:17:30 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,399 bytes |
| コンパイル時間 | 3,446 ms |
| コンパイル使用メモリ | 142,456 KB |
| 実行使用メモリ | 5,312 KB |
| 最終ジャッジ日時 | 2024-11-22 07:02:46 |
| 合計ジャッジ時間 | 5,902 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 14 WA * 8 |
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int C[10];
int N;
string K;
string f(int d) {
string res = "";
int CC[10];
memcpy(CC, C, sizeof(C));
for (int i = 1; i <= N; ++i) {
int v = K[i - 1] - '0';
if (i < d) {
if (CC[v] > 0) {
CC[v]--;
res += to_string(v);
} else {
return res;
}
} else if (i == d) {
bool found = false;
for (int j = v + 1; j <= 9 && not found; ++j) {
if (CC[j] == 0) continue;
found = true;
CC[j]--;
res += to_string(j);
}
if (not found) {
return res;
}
} else {
for (int j = 1; j <= 9; ++j) {
if (CC[j] == 0) continue;
CC[j]--;
res += to_string(j);
break;
}
}
}
return res;
}
int main() {
cin >> N >> K;
for (int i = 1; i <= 9; ++i) {
cin >> C[i];
}
if (f(1).size() != N) {
cout << -1 << endl;
} else {
int ok = 1;
int ng = N;
while (abs(ok - ng) >= 2) {
int d = (ok + ng) / 2;
string res = f(d);
if (res.size() == N) {
ok = d;
} else {
ng = d;
}
}
cout << f(ok) << endl;
}
return 0;
}
siman