Submission #68189055


Source Code Expand

/*******************************
  @tiger2005 / 2025-08-03 20:06:19
  "B - Swap If Equal Sum" From AtCoder - AtCoder Regular Contest 203 (Div. 2)
  # https://atcoder.jp/contests/arc203/tasks/arc203_b
  1024 MB / 2000 ms
*******************************/
#include <bits/stdc++.h>
#include <numeric>
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

/*
  basic operations:
  01 <=> 1
  10 <=> 1
  00 <=> 0
*/

int main() {
  multiCase() {
    int n; cin >> n;
    auto A = getv(n);
    auto B = getv(n);
    int sA = accumulate(ALL(A), 0);
    int sB = accumulate(ALL(B), 0);
    if (sA != sB)
      puts("No");
    else if (sA == 0 || sA >= 2)
      puts("Yes");
    else {
      if (A == B)
        puts("Yes");
      else if (A[0] == 1 || A[n - 1] == 1 || B[0] == 1 || B[n - 1] == 1)
        puts("No");
      else
        puts("Yes");
    }
  }
  return 0;
}

Submission Info

Submission Time
Task B - Swap If Equal Sum
User tiger2005
Language C++ 20 (gcc 12.2)
Score 500
Code Size 8161 Byte
Status AC
Exec Time 10 ms
Memory 4772 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 1
AC × 58
Set Name Test Cases
Sample sample.txt
All 1_1.txt, 1_10.txt, 1_2.txt, 1_3.txt, 1_4.txt, 1_5.txt, 1_6.txt, 1_7.txt, 1_8.txt, 1_9.txt, 2_1.txt, 2_10.txt, 2_2.txt, 2_3.txt, 2_4.txt, 2_5.txt, 2_6.txt, 2_7.txt, 2_8.txt, 2_9.txt, 3_1.txt, 3_10.txt, 3_11.txt, 3_12.txt, 3_13.txt, 3_14.txt, 3_15.txt, 3_16.txt, 3_17.txt, 3_18.txt, 3_19.txt, 3_2.txt, 3_20.txt, 3_3.txt, 3_4.txt, 3_5.txt, 3_6.txt, 3_7.txt, 3_8.txt, 3_9.txt, 4_1.txt, 4_10.txt, 4_11.txt, 4_12.txt, 4_13.txt, 4_14.txt, 4_15.txt, 4_16.txt, 4_2.txt, 4_3.txt, 4_4.txt, 4_5.txt, 4_6.txt, 4_7.txt, 4_8.txt, 4_9.txt, 5.txt, sample.txt
Case Name Status Exec Time Memory
1_1.txt AC 4 ms 3872 KiB
1_10.txt AC 4 ms 3876 KiB
1_2.txt AC 5 ms 4364 KiB
1_3.txt AC 4 ms 4060 KiB
1_4.txt AC 4 ms 4096 KiB
1_5.txt AC 4 ms 4276 KiB
1_6.txt AC 4 ms 3816 KiB
1_7.txt AC 4 ms 4092 KiB
1_8.txt AC 5 ms 4096 KiB
1_9.txt AC 4 ms 4052 KiB
2_1.txt AC 4 ms 3592 KiB
2_10.txt AC 4 ms 3524 KiB
2_2.txt AC 4 ms 3560 KiB
2_3.txt AC 4 ms 3528 KiB
2_4.txt AC 4 ms 3628 KiB
2_5.txt AC 4 ms 3596 KiB
2_6.txt AC 4 ms 3560 KiB
2_7.txt AC 4 ms 3588 KiB
2_8.txt AC 4 ms 3524 KiB
2_9.txt AC 4 ms 3532 KiB
3_1.txt AC 4 ms 4612 KiB
3_10.txt AC 4 ms 4684 KiB
3_11.txt AC 5 ms 4540 KiB
3_12.txt AC 5 ms 4672 KiB
3_13.txt AC 5 ms 4672 KiB
3_14.txt AC 5 ms 4624 KiB
3_15.txt AC 5 ms 4632 KiB
3_16.txt AC 4 ms 4576 KiB
3_17.txt AC 4 ms 4636 KiB
3_18.txt AC 5 ms 4612 KiB
3_19.txt AC 4 ms 4772 KiB
3_2.txt AC 4 ms 4616 KiB
3_20.txt AC 4 ms 4632 KiB
3_3.txt AC 4 ms 4572 KiB
3_4.txt AC 5 ms 4772 KiB
3_5.txt AC 5 ms 4632 KiB
3_6.txt AC 5 ms 4580 KiB
3_7.txt AC 5 ms 4704 KiB
3_8.txt AC 5 ms 4668 KiB
3_9.txt AC 5 ms 4540 KiB
4_1.txt AC 5 ms 3488 KiB
4_10.txt AC 5 ms 3460 KiB
4_11.txt AC 5 ms 3492 KiB
4_12.txt AC 5 ms 3456 KiB
4_13.txt AC 5 ms 3448 KiB
4_14.txt AC 5 ms 3460 KiB
4_15.txt AC 5 ms 3524 KiB
4_16.txt AC 2 ms 3480 KiB
4_2.txt AC 5 ms 3360 KiB
4_3.txt AC 5 ms 3524 KiB
4_4.txt AC 5 ms 3484 KiB
4_5.txt AC 5 ms 3404 KiB
4_6.txt AC 5 ms 3436 KiB
4_7.txt AC 5 ms 3464 KiB
4_8.txt AC 5 ms 3476 KiB
4_9.txt AC 5 ms 3488 KiB
5.txt AC 10 ms 3556 KiB
sample.txt AC 1 ms 3424 KiB