結果
| 問題 | No.3448 ABBBBBBBBC |
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2025-12-28 06:53:42 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 80 ms / 2,000 ms |
| コード長 | 1,874 bytes |
| 記録 | |
| コンパイル時間 | 1,809 ms |
| コンパイル使用メモリ | 215,072 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-02-20 20:51:37 |
| 合計ジャッジ時間 | 2,849 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
long long N, K;
cin >> N >> K;
long long k0 = K - 1; // 0-index
long long per_a = 72LL * N; // 9 * (8N)
long long a_idx = k0 / per_a; // 0..8
int a = (int)a_idx + 1;
k0 %= per_a;
long long per_ab = 8LL * N;
long long b_idx = k0 / per_ab; // 0..8
long long r = k0 % per_ab; // rank inside (a,b)
// map b_idx -> b in sorted digits excluding a
int b = -1;
{
int cnt = 0;
for (int d = 0; d <= 9; d++) {
if (d == a) continue;
if (cnt == b_idx) { b = d; break; }
cnt++;
}
}
// build C_low and C_high (digits excluding a,b)
vector<int> low, high;
for (int d = 0; d <= 9; d++) {
if (d == a || d == b) continue;
if (d < b) low.push_back(d);
else if (d > b) high.push_back(d);
}
long long L = (long long)low.size();
long long H = (long long)high.size(); // = 8 - L
long long t;
int c;
if (L > 0 && r < L * N) {
t = r / L; // 0..N-1
long long idxc = r % L;
c = low[(size_t)idxc];
} else {
long long r2 = r - L * N; // if L==0, this is r
// H must be > 0 because L is 0..8 and total is 8
t = (N - 1) - (r2 / H); // descending
long long idxc = r2 % H;
c = high[(size_t)idxc];
}
long long len = t + 3; // |U| = t + 3
cout << len << " " << a << " " << b << " " << c << "\n";
}
return 0;
}
potato167