QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#794121 | #9799. Magical Palette | ucup-team008# | WA | 41ms | 7496kb | C++17 | 5.1kb | 2024-11-30 11:23:14 | 2024-11-30 11:23:14 |
Judging History
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <omp.h>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(1) cerr
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
template<class T>
bool updmin(T& a, T b) {
if(b < a) {
a = b;
return true;
}
return false;
}
template<class T>
bool updmax(T& a, T b) {
if(b > a) {
a = b;
return true;
}
return false;
}
typedef int64_t ll;
void slow(int r, int c) {
int mod = (r*c);
vector<int> a(r), b(c);
vector<bool> seen(r*c);
auto dfs = y_combinator([&](auto self, int idx) -> void {
if(idx == r + c) {
debug(a, b);
return;
}
if(idx >= r) {
for(int x = idx == r ? 1 : b[idx-r-1] + 1; x <= r*c; x++) {
b[idx-r] = x;
bool can = true;
set<int> has;
for(int out: a) {
if(seen[(out*x)%mod]) {
can = false;
break;
}
has.insert((out*x)%mod);
}
if(sz(has) != sz(a)) continue;
if(can) {
for(int out: a) {
assert(!seen[(out*x)%mod]);
seen[(out*x)%mod] = true;
}
self(idx+1);
for(int out: a) {
assert(seen[(out*x)%mod]);
seen[(out*x)%mod] = false;
}
}
}
}
else {
for(int x = idx == 0 ? 1 : a[idx-1] + 1; x <= r*c; x++) {
a[idx] = x;
self(idx+1);
}
}
});
a[0] = 1;
dfs(1);
}
void fast(int r, int c) {
if(gcd(r, c) > 1) return void(cout << "No\n");
int mod = r*c;
vector<int> a(r), b(c);
bool fswp = r > c;
if(fswp) {
swap(a, b);
}
a[0] = 1;
for(int i = 1; i < sz(a); i++) {
a[i] = a[i-1] + sz(b);
}
vector<bool> have(r*c);
b[0] = 1;
for(int out: a) have[out] = true;
for(int i = 1; i < sz(b); i++) {
int nv = b[i-1]+sz(a);
while(true) {
assert(nv <= r*c);
bool valid = true;
for(int out: a) {
int cand = (out*ll(nv))%mod;
if(have[cand]) {
valid = false;
break;
}
}
if(valid) {
b[i] = nv;
for(int out: a) {
int cand = (out*ll(nv))%mod;
assert(!have[cand]);
have[cand] = true;
}
break;
}
nv++;
}
}
if(fswp) {
swap(a, b);
}
cout << "Yes\n";
for(int i = 0; i < r; i++) cout << a[i] << " \n"[i == r-1];
for(int i = 0; i < c; i++) cout << b[i] << " \n"[i == c-1];
}
void rsolve() {
int r, c;
cin >> r >> c;
fast(r, c);
}
void solve() {
int t;
cin >> t;
while(t--) rsolve();
}
// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
// are you not using modint when you should
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
2 2 3 2 2
output:
Yes 1 4 1 3 5 No
result:
ok 2 cases (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 41ms
memory: 7496kb
input:
1 1 1000000
output:
Yes 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
result:
wrong answer Integer parameter [name=b[1000000]] equals to 1000000, violates the range [0, 999999] (test case 1)