Submission #67305527
Source Code Expand
/*******************************
@tiger2005 / 2025-07-05 20:03:20
"D - Make Geometric Sequence" From AtCoder - Denso Create Programming Contest 2025(AtCoder Beginner Contest 413)
# https://atcoder.jp/contests/abc413/tasks/abc413_d
1024 MB / 2000 ms
*******************************/
#include <bits/stdc++.h>
using namespace std;
#define NO_TEMPLATE_IMPORT
// #define FREAD
const int Md3 = 998244353, Md7 = 1e9 + 7, Md9 = 1e9 + 9;
const int Md = Md3;
// $START - misc/io.h
namespace io_lib {
#ifdef FREAD
#define MAXBUFFERSIZE 1000000
inline char fgetc() { static char buf[MAXBUFFERSIZE + 5], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXBUFFERSIZE, stdin), p1 == p2) ? EOF : *p1++; }
#undef MAXBUFFERSIZE
#define getchar fgetc
#endif
#define gc getchar
struct IOReader {
template <typename T, typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
inline const IOReader& operator>>(T& a) const {
a = 0; bool flg = false; char ch = gc();
while (ch < '0' || ch > '9') { if (ch == '-') flg ^= 1; ch = gc(); }
while (ch >= '0' && ch <= '9') { a = (a << 3) + (a << 1) + (ch ^ '0'); ch = gc(); }
if (flg) a = -a; return *this;
}
inline const IOReader& operator>>(string& a) const {
a.clear(); char ch = gc();
while (isspace(ch) && ch != EOF) ch = gc();
while (!isspace(ch) && ch != EOF) a += ch, ch = gc();
return *this;
}
inline const IOReader& operator>>(char* a) const {
char ch = gc();
while (isspace(ch) && ch != EOF) ch = gc();
while (!isspace(ch) && ch != EOF) *(a++) = ch, ch = gc();
*a = '\0'; return *this;
}
inline const IOReader& operator>>(char& a) const { a = gc(); while (isspace(a)) a = gc(); return *this; }
template <typename T, typename std::enable_if<std::is_floating_point<T>::value, int>::type = 0>
inline const IOReader& operator>>(T& a) const {
a = 0; bool flg = false; char ch = gc();
while ((ch < '0' || ch > '9') && ch != '.') { if (ch == '-') flg ^= 1; ch = gc(); }
while (ch >= '0' && ch <= '9') { a = a * 10 + (ch ^ '0'); ch = gc(); }
if (ch == '.') { ch = gc(); T p = 0.1; while (ch >= '0' && ch <= '9') { a += p * (ch ^ '0'); ch = gc(); p *= 0.1; } }
if (flg) a = -a; return *this;
}
template <typename T1, typename T2>
inline const IOReader& operator>>(std::pair<T1, T2>& p) const { return operator>>(p.first), operator>>(p.second), *this; }
template <typename T, std::size_t N>
inline const IOReader& operator>>(std::array<T, N>& p) const { for (std::size_t i = 0; i < N; i ++) operator>>(p[i]); return *this; }
template <typename... Ts>
inline const IOReader& operator>>(std::tuple<Ts...>& p) const;
};
const IOReader io;
#undef gc
template <typename T> void read(T& val) { io >> val; }
template <typename T> void read(int l, int r, T& A) { for (int i = l; i <= r; i++) io >> A[i]; }
template <typename T> void write(const T& A, int l, int r, const char* sp, const char* end = "") { for (int i = l; i <= r; i++) printf(sp, A[i]); printf("%s", end); }
template <typename T> void write(const T& A, const char* sp, const char* end = "") {for (auto e : A) printf(sp, e); printf("%s", end); }
template <typename T = int> T read() { T res; io >> res; return res; }
template <typename T, int N> std::array<T, N> read() { return read<std::array<T, N>>(); }
template <typename Tuple, typename Func, size_t... N> void func_call_tuple(Tuple& t, Func&& func, std::index_sequence<N...>) { static_cast<void>(std::initializer_list<int>{(func(std::get<N>(t)), 0)...}); }
template <typename... Args, typename Func> void travel_tuple(std::tuple<Args...>& t, Func&& func) { func_call_tuple(t, std::forward<Func>(func), std::make_index_sequence<sizeof...(Args)>{}); }
template <typename... Ts> tuple<Ts...> reads() { tuple<Ts...> res; travel_tuple(res, [&](auto&& val) { io >> val; }); return res; }
template <typename... Ts> inline const IOReader& IOReader::operator>>(std::tuple<Ts...>& p) const { return p = reads<Ts...>(), *this; }
template <typename T = int> vector<T> getv(int n, int start = 0) { vector<T> res(start + n); for (int i = start; i < start + n; i++) io >> res[i]; return res; }
template <typename T, typename T1, typename T2, typename... Ts> vector<tuple<T, T1, T2, Ts...>> getv(int n, int start = 0) { vector<tuple<T, T1, T2, Ts...>> res(start + n); for (int i = start; i < start + n; i++) io >> res[i]; return res; }
template <typename T1, typename T2> vector<pair<T1, T2>> getv(int n, int start = 0) { vector<pair<T1, T2>> res(start + n); for (int i = start; i < start + n; i++) io >> res[i]; return res; }
} // namespace io_lib
using namespace io_lib;
// $END - misc/io.h
// #START - misc/defs.h
namespace defs {
inline void Yes(bool x, string str = "") { printf("%s%s", (x) ? "Yes" : "No", str.c_str()); }
inline void YES(bool x, string str = "") { printf("%s%s", (x) ? "YES" : "NO", str.c_str()); }
inline void yes(bool x, string str = "") { printf("%s%s", (x) ? "yes" : "no", str.c_str()); }
inline void Yes(bool x, char ch) { printf("%s%c", (x) ? "Yes" : "No", ch); }
inline void YES(bool x, char ch) { printf("%s%c", (x) ? "YES" : "NO", ch); }
inline void yes(bool x, char ch) { printf("%s%c", (x) ? "yes" : "no", ch); }
#define openFile(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)
#define closeFile() fclose(stdin), fclose(stdout)
#define ALL(x) std::begin(x), std::end(x)
#define multiCase() \
int totCases; cin >> totCases; \
for (int currCase = 1; currCase <= totCases; currCase++)
using i32 = int; using u32 = unsigned int;
using i64 = long long; using u64 = unsigned long long;
using i128 = __int128; using u128 = __uint128_t;
using f32 = float; using f64 = double;
template <typename T> void sort(T& v) { sort(ALL(v)); }
template <typename T> T sorted(T v) { return sort(v), v; }
template <typename T, typename T2> void sort(T& v, T2 compare) { sort(ALL(v), compare); }
template <typename T, typename T2> T sorted(T v, T2 compare) { return sort(v, compare), v; }
template <typename T> void reverse(T& v) { reverse(ALL(v)); }
template <typename T> T reversed(T v) { return reverse(v), v; }
template <typename T> void unique(vector<T>& v) { v.erase(unique(ALL(v)), v.end()); }
template <typename T> vector<T> uniqued(vector<T> v) { return unique(v), v; }
bool in(char ch, string str) { for (auto x : str) if (ch == x) return true; return false; }
template <typename T> bool in(T v, vector<T> V) { for (auto x : V) if (v == x) return true; return false; }
template <typename T> auto index(const vector<T>& v, int n = 0) { vector<pair<int, T>> res; for (int i = 0; i < (int) v.size(); i++) res.push_back({n++, v[i]}); return res; }
template <typename T> auto pairwise(const vector<T>& v) { vector<pair<T, T>> res; for (int i = 1; i < (int)v.size(); i ++) res.push_back({v[i - 1], v[i]}); return res; }
auto index(const string& v, int n = 0) { return index(vector<char>(v.begin(), v.end()), n); }
auto pairwise(const string& v) { return pairwise(vector<char>(v.begin(), v.end())); }
template <typename T> bool ckmax(T& a, const T& b) { return a < b ? (a = b, true) : false; }
template <typename T> bool ckmin(T& a, const T& b) { return b < a ? (a = b, true) : false; }
template <typename T, typename T2> bool ckmax(T& a, T2 b) { return a < b ? (a = b, true) : false; }
template <typename T, typename T2> bool ckmin(T& a, T2 b) { return b < a ? (a = b, true) : false; }
} // namespace defs
using namespace defs;
// #END - misc/defs.h
// #include "lib/math/z.h"
#define cin io
int main() {
multiCase() {
int n; cin >> n;
auto a = getv(n);
vector<int> u, v;
for (auto e : a)
if (e > 0)
u.push_back(e);
else
v.push_back(e);
sort(u);
sort(v); reverse(v);
auto check = [&] (vector<int> vec) {
bool flg = true;
int n = vec.size();
if (n == 0)
return false;
for (int i = 2; i < n; i ++)
flg &= 1ll * vec[i - 1] * vec[i - 1] == 1ll * vec[i - 2] * vec[i];
return flg;
};
auto try_merge = [&] (vector<int> a, vector<int> b) {
vector<int> res;
int n = a.size(), m = b.size();
if (n != m && n != m + 1)
return res;
for (int i = 0; i < n; i ++) {
res.push_back(a[i]);
if (i < m)
res.push_back(b[i]);
}
return res;
};
bool flg = false;
if (u.empty()) {
flg |= check(v);
} else if (v.empty()) {
flg |= check(u);
} else {
flg |= check(try_merge(u, v));
flg |= check(try_merge(v, u));
}
Yes(flg, "\n");
}
return 0;
}
Submission Info
Submission Time
2025-07-05 21:08:07+0900
Task
D - Make Geometric Sequence
User
tiger2005
Language
C++ 20 (gcc 12.2)
Score
425
Code Size
8750 Byte
Status
AC
Exec Time
22 ms
Memory
5684 KiB
Compile Error
Main.cpp: In member function ‘const io_lib::IOReader& io_lib::IOReader::operator>>(T&) const’:
Main.cpp:30:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
30 | if (flg) a = -a; return *this;
| ^~
Main.cpp:30:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
30 | if (flg) a = -a; return *this;
| ^~~~~~
Main.cpp: In member function ‘const io_lib::IOReader& io_lib::IOReader::operator>>(T&) const’:
Main.cpp:51:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
51 | if (flg) a = -a; return *this;
| ^~
Main.cpp:51:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
51 | if (flg) a = -a; return *this;
| ^~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
425 / 425
Status
Set Name
Test Cases
Sample
00_sample_00.txt
All
00_sample_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 02_handmade_31.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
1 ms
3644 KiB
01_random_01.txt
AC
9 ms
3648 KiB
01_random_02.txt
AC
20 ms
4692 KiB
01_random_03.txt
AC
21 ms
5404 KiB
01_random_04.txt
AC
18 ms
3584 KiB
01_random_05.txt
AC
19 ms
4020 KiB
01_random_06.txt
AC
5 ms
3584 KiB
01_random_07.txt
AC
10 ms
5400 KiB
01_random_08.txt
AC
18 ms
3628 KiB
01_random_09.txt
AC
18 ms
3736 KiB
01_random_10.txt
AC
11 ms
3568 KiB
01_random_11.txt
AC
20 ms
4548 KiB
01_random_12.txt
AC
18 ms
3580 KiB
01_random_13.txt
AC
18 ms
3592 KiB
01_random_14.txt
AC
18 ms
3748 KiB
01_random_15.txt
AC
18 ms
3828 KiB
01_random_16.txt
AC
18 ms
3612 KiB
01_random_17.txt
AC
18 ms
3648 KiB
01_random_18.txt
AC
14 ms
3648 KiB
01_random_19.txt
AC
12 ms
5684 KiB
01_random_20.txt
AC
9 ms
3640 KiB
01_random_21.txt
AC
20 ms
4580 KiB
01_random_22.txt
AC
19 ms
3712 KiB
01_random_23.txt
AC
11 ms
3580 KiB
01_random_24.txt
AC
22 ms
5368 KiB
01_random_25.txt
AC
18 ms
3564 KiB
01_random_26.txt
AC
18 ms
3640 KiB
01_random_27.txt
AC
15 ms
3824 KiB
01_random_28.txt
AC
20 ms
4568 KiB
01_random_29.txt
AC
18 ms
3560 KiB
01_random_30.txt
AC
10 ms
3844 KiB
02_handmade_31.txt
AC
1 ms
3628 KiB