結果
| 問題 | No.3623 2-Letter Shiritori 2 |
| コンテスト | |
| ユーザー |
👑 Nachia
|
| 提出日時 | 2026-08-14 21:26:46 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| + 307µs | |
| コード長 | 1,769 bytes |
| 記録 | |
| コンパイル時間 | 631 ms |
| コンパイル使用メモリ | 107,428 KB |
| 実行使用メモリ | 7,340 KB |
| 最終ジャッジ日時 | 2026-08-14 21:26:52 |
| 合計ジャッジ時間 | 1,403 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 |
ソースコード
#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
// disable assert
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B> void chmax(A& l, const B& r){ if(l < r) l = r; }
template <class A, class B> void chmin(A& l, const B& r){ if(r < l) l = r; }
pair<V<int>, V<int>> eulerian_trail(
int N, const V<pair<int, int>>& edges, bool directed, int start = -1) {
int M = edges.size();
if(!M) return { {0}, {} };
V<int> X(M), D(N);
V<V<int>> G(N);
REP(m,M){
auto [u,v] = edges[m];
G[u].push_back(m);
if (!directed) G[v].push_back(m);
X[m] = u + v;
}
if(start < 0) {
start = edges[0].first;
for(auto [u,v] : edges){
D[u] += 1;
D[v] += directed ? -1 : 1;
}
REP(i, N) if(D[i] % 2 == 1) start = i;
}
V<int> H(M+1,start), E(M), U(M, 0), K(N);
REP(i,N) K[i] = G[i].size();
int p = 0, q = M;
while (q) {
int v = H[p];
while (0 < K[v]-- && U[G[v][K[v]]]) ;
if (K[v] < 0) {
if (!p) return {{-1}, {-1}};
H[q--] = H[p--];
E[q] = E[p];
} else {
auto e = G[v][K[v]];
U[e] = 1;
E[p++] = e;
H[p] = X[e] - v;
}
}
REP(i, M) if(X[E[i]] != H[i] + H[i + 1]) return { {-1}, {-1} };
return {H, E};
}
void testcase(){
V<pair<int,int>> edges;
REP(i,26) REP(j,26) edges.push_back({ i, j });
auto ei = eulerian_trail(26, edges, true).second;
for(auto e : ei){
cout << char('A' + e / 26) << char('A' + e % 26) << "\n";
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
// ll T; cin >> T; REP(t,T)
testcase();
return 0;
}
Nachia