結果
| 問題 | No.3585 Make Ends Meet (Easy) |
| コンテスト | |
| ユーザー |
Iroha_3856
|
| 提出日時 | 2026-07-10 22:04:59 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,648 bytes |
| 記録 | |
| コンパイル時間 | 4,254 ms |
| コンパイル使用メモリ | 385,292 KB |
| 実行使用メモリ | 12,032 KB |
| 最終ジャッジ日時 | 2026-07-10 22:05:12 |
| 合計ジャッジ時間 | 6,522 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 WA * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using mint = atcoder::modint998244353;
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define siz(x) (int)x.size()
#define debug(x) cout << #x << " : " << endl; for (auto u : x) cout << u << " "; cout << endl
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int inf = 1e9;
const ll INF = 4e18;
template<class T> using spq = priority_queue<T, vector<T>, greater<T>>;
vector<int> di = {1, 0, -1, 0}, dj = {0, 1, 0, -1};
int main() {
int N, M, K; cin >> N >> M >> K;
int R = N * (N - 1) / 2 - M;
if (R < N - 1) {
cout << "No\n";
return 0;
}
// vector<int> A(K + 1, 1);
// auto score = [&](vector<int> X) -> int {
// int ret = 0;
// rep(i, 0, K) ret += A[i] * A[i + 1];
// rep(i, 0, K + 1) ret += A[i] * (A[i] - 1) / 2;
// return ret;
// };
// rep(_, 0, N - K - 1) {
// int amx = -1, mx = -1;
// rep(j, 1, K + 1) {
// A[j]++;
// if (chmax(mx, score(A))) amx = j;
// A[j]--;
// }
// A[amx]++;
// }
//謎の貪欲をしなくてもdpできますやん!!
//i, used, last
vector dp(K + 1, vector(N + 1, vector<int>(N + 1, -1)));
vector from(K + 1, vector(N + 1, vector<int>(N + 1, -1)));
dp[0][1][1] = 0;
rep(i, 0, K) {
rep(j, 0, N + 1) rep(k, 0, N + 1) {
if (dp[i][j][k] == -1) continue;
rep(l, 1, N + 1) {
if (j + l <= N) {
if (chmax(dp[i + 1][j + l][l], dp[i][j][k] + k * l + l * (l - 1) / 2)) {
from[i + 1][j + l][l] = k;
}
}
}
}
}
int ci = K, cj = 0, ck = 0;
rep(j, 0, N + 1) rep(k, 0, N + 1) {
if (dp[K][j][k] > dp[ci][cj][ck]) {
cj = j; ck = k;
}
}
int sc = dp[K][cj][ck];
vector<int> A;
while(true) {
A.push_back(ck);
int memo = from[ci][cj][ck];
ci--;
cj -= ck;
ck = memo;
if (ci == -1) break;
}
reverse(all(A));
if (R <= sc) {
cout << "Yes\n";
vector<vector<int>> V(K + 1);
int c = 0;
rep(i, 0, K + 1) {
rep(_, 0, A[i]) V[i].push_back(c++);
}
vector<vector<bool>> choose(N, vector<bool>(N, false));
vector<pair<int, int>> choosable;
rep(i, 0, K) {
rep(j, 0, A[i]) rep(k, 0, A[i + 1]) {
if (j == 0) {
choose[V[i][j]][V[i + 1][k]] = true;
}
else {
choosable.push_back({V[i][j], V[i + 1][k]});
}
}
}
rep(i, 0, K + 1) {
rep(j, 0, A[i]) rep(k, j + 1, A[i]) {
choosable.push_back({V[i][j], V[i][k]});
}
}
// cout << "choosable : " << "\n";
// for (auto[u, v] : choosable) {
// cout << u << " " << v << "\n";
// }
// cout << "====" << endl;
int chosen = N - 1;
// assert(siz(choosable) >= R - chosen);s
rep(i, 0, R - chosen) {
auto[u, v] = choosable[i];
choose[u][v] = true;
}
rep(i, 0, N) rep(j, i + 1, N) {
if (not choose[i][j]) cout << i + 1 << " " << j + 1 << "\n";
}
}
else {
cout << "No\n";
}
}
Iroha_3856