結果

問題 No.2947 Sing a Song
ユーザー ecotteaecottea
提出日時 2024-10-25 21:28:21
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 7,985 bytes
コンパイル時間 4,623 ms
コンパイル使用メモリ 263,464 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-25 21:28:34
合計ジャッジ時間 7,221 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,820 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 3 ms
6,820 KB
testcase_05 AC 2 ms
6,824 KB
testcase_06 AC 3 ms
6,816 KB
testcase_07 AC 3 ms
6,816 KB
testcase_08 AC 3 ms
6,820 KB
testcase_09 AC 2 ms
6,820 KB
testcase_10 AC 2 ms
6,820 KB
testcase_11 AC 2 ms
6,816 KB
testcase_12 AC 4 ms
6,820 KB
testcase_13 AC 4 ms
6,816 KB
testcase_14 AC 2 ms
6,820 KB
testcase_15 AC 3 ms
6,816 KB
testcase_16 AC 2 ms
6,816 KB
testcase_17 AC 3 ms
6,816 KB
testcase_18 AC 3 ms
6,816 KB
testcase_19 AC 3 ms
6,820 KB
testcase_20 AC 6 ms
6,820 KB
testcase_21 AC 2 ms
6,824 KB
testcase_22 AC 3 ms
6,820 KB
testcase_23 AC 5 ms
6,816 KB
testcase_24 AC 5 ms
6,820 KB
testcase_25 AC 4 ms
6,820 KB
testcase_26 AC 7 ms
6,816 KB
testcase_27 AC 11 ms
6,820 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:36:54: warning: 'y' may be used uninitialized [-Wmaybe-uninitialized]
   36 | #define rep(i, n) for(int i = 0, i##_len = int(n); i < i##_len; ++i) // 0 から n-1 まで昇順
      |                                                      ^
main.cpp:235:24: note: 'y' was declared here
  235 |                 int x, y;
      |                        ^
main.cpp:36:54: warning: 'x' may be used uninitialized [-Wmaybe-uninitialized]
   36 | #define rep(i, n) for(int i = 0, i##_len = int(n); i < i##_len; ++i) // 0 から n-1 まで昇順
      |                                                      ^
main.cpp:235:21: note: 'x' was declared here
  235 |                 int x, y;
      |                     ^

ソースコード

diff #
プレゼンテーションモードにする

#ifndef HIDDEN_IN_VS //
//
#define _CRT_SECURE_NO_WARNINGS
//
#include <bits/stdc++.h>
using namespace std;
//
using ll = long long; using ull = unsigned long long; // -2^63 2^63 = 9e18int -2^31 2^31 = 2e9
using pii = pair<int, int>; using pll = pair<ll, ll>; using pil = pair<int, ll>; using pli = pair<ll, int>;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vvvvi = vector<vvvi>;
using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>; using vvvvl = vector<vvvl>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vc = vector<char>; using vvc = vector<vc>; using vvvc = vector<vvc>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
template <class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
using Graph = vvi;
//
const double PI = acos(-1);
int DX[4] = { 1, 0, -1, 0 }; // 4
int DY[4] = { 0, 1, 0, -1 };
int INF = 1001001001; ll INFL = 4004004003094073385LL; // (int)INFL = INF, (int)(-INFL) = -INF;
//
struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } fastIOtmp;
//
#define all(a) (a).begin(), (a).end()
#define sz(x) ((int)(x).size())
#define lbpos(a, x) (int)distance((a).begin(), std::lower_bound(all(a), (x)))
#define ubpos(a, x) (int)distance((a).begin(), std::upper_bound(all(a), (x)))
#define Yes(b) {cout << ((b) ? "Yes\n" : "No\n");}
#define rep(i, n) for(int i = 0, i##_len = int(n); i < i##_len; ++i) // 0 n-1
#define repi(i, s, t) for(int i = int(s), i##_end = int(t); i <= i##_end; ++i) // s t
#define repir(i, s, t) for(int i = int(s), i##_end = int(t); i >= i##_end; --i) // s t
#define repe(v, a) for(const auto& v : (a)) // a
#define repea(v, a) for(auto& v : (a)) // a
#define repb(set, d) for(int set = 0, set##_ub = 1 << int(d); set < set##_ub; ++set) // d
#define repis(i, set) for(int i = lsb(set), bset##i = set; i < 32; bset##i -= 1 << i, i = lsb(bset##i)) // set
#define repp(a) sort(all(a)); for(bool a##_perm = true; a##_perm; a##_perm = next_permutation(all(a))) // a
#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} //
#define EXIT(a) {cout << (a) << endl; exit(0);} //
#define inQ(x, y, u, l, d, r) ((u) <= (x) && (l) <= (y) && (x) < (d) && (y) < (r)) //
//
template <class T> inline ll powi(T n, int k) { ll v = 1; rep(i, k) v *= n; return v; }
template <class T> inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // true
    
template <class T> inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // true
    
template <class T> inline T getb(T set, int i) { return (set >> i) & T(1); }
template <class T> inline T smod(T n, T m) { n %= m; if (n < 0) n += m; return n; } // mod
//
template <class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template <class T> inline istream& operator>>(istream& is, vector<T>& v) { repea(x, v) is >> x; return is; }
template <class T> inline vector<T>& operator--(vector<T>& v) { repea(x, v) --x; return v; }
template <class T> inline vector<T>& operator++(vector<T>& v) { repea(x, v) ++x; return v; }
#endif //
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#ifdef _MSC_VER
#include "localACL.hpp"
#endif
using mint = modint998244353;
//using mint = static_modint<1000000009>;
//using mint = modint; // mint::set_mod(m);
namespace atcoder {
inline istream& operator>>(istream& is, mint& x) { ll x_; is >> x_; x = x_; return is; }
inline ostream& operator<<(ostream& os, const mint& x) { os << x.val(); return os; }
}
using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>; using vvvvm = vector<vvvm>; using pim = pair<int, mint>;
#endif
#ifdef _MSC_VER // Visual Studio
#include "local.hpp"
#else // gcc
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(ll n) { return __builtin_popcountll(n); }
inline int lsb(int n) { return n != 0 ? __builtin_ctz(n) : 32; }
inline int lsb(ll n) { return n != 0 ? __builtin_ctzll(n) : 64; }
inline int msb(int n) { return n != 0 ? (31 - __builtin_clz(n)) : -1; }
inline int msb(ll n) { return n != 0 ? (63 - __builtin_clzll(n)) : -1; }
#define dump(...)
#define dumpel(...)
#define dump_list(v)
#define dump_mat(v)
#define input_from_file(f)
#define output_to_file(f)
#define Assert(b) { if (!(b)) { vc MLE(1<<30); EXIT(MLE.back()); } } // RE MLE
#endif
//O(log max(|a|, |b|))
/*
* g = GCD(a, b) ≧ 0 a x + b y = g (x, y)
* |x| + |y|
*/
template <class T>
T extended_gcd(T a, T b, T& x, T& y) {
// : https://ashiato45.hatenablog.jp/entry/2018/11/04/172848
// verify : https://atcoder.jp/contests/abc340/tasks/abc340_f
//
//
//
//
// [1 0] [a] [a]
// [0 1].[b] = [b]
// i
// [x_i y_i ] [a] [a_i]
// [x_(i+1) y_(i+1)].[b] = [b_i]
//
// a_i = q b_i + r
// q, r
// [0 1] [a_i] = [b_i]
// [1 -q].[b_i] = [ r ]
//
// [0 1] [x_i y_i ] [a] [b_i]
// [1 -q].[x_(i+1) y_(i+1)].[b] = [ r ]
//
// [x y] [a] [±1]
// [* *].[b] = [ 0]
// 1
if (a == 0 && b == 0) {
x = y = 0;
return 0;
}
x = 1, y = 0;
T nx = 0, ny = 1;
while (b != 0) {
T q = a / b;
T r = a % b;
x -= q * nx;
y -= q * ny;
swap(nx, x);
swap(ny, y);
a = b;
b = r;
}
if (a < 0) {
x = -x;
y = -y;
a = -a;
}
return a;
}
//O(log max(|a|, |b|))
/*
* a x + b y = c (x, y) x
* GCD(a, b) ≧ 0 -1
*
*
*/
template <class T = ll>
T bezout(T a, T b, T c, T& x, T& y) {
// verify : https://atcoder.jp/contests/abc340/tasks/abc340_f
if (b == 0) {
if (a == 0) {
if (c == 0) {
x = y = 0;
return 0;
}
else {
return -1;
}
}
if (c % a == 0) {
x = c / a;
y = 0;
return abs(a);
}
else {
return -1;
}
}
if (b < 0) {
a *= -1;
b *= -1;
c *= -1;
}
// a x + b y = g = gcd(a, b)
T g = extended_gcd(a, b, x, y);
if (c % g != 0) return -1;
a /= g;
b /= g;
c /= g;
x *= c % b; // c
x %= b;
if (x < 0) x += b;
y = (c - a * x) / b;
return g;
}
int main() {
// input_from_file("input.txt");
// output_to_file("output.txt");
int n; string s, t;
cin >> n >> s >> t;
int ls = sz(s), lt = sz(t);
vi a(n);
cin >> a;
rep(i, n) {
int x, y;
auto g = bezout(lt, ls, a[i], x, y);
rep(hoge, y) {
if (hoge != 0) cout << " ";
cout << s;
}
rep(hoge, x) {
cout << " " << t;
}
cout << "\n";
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0