QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#481584 | #5438. Half Mixed | orz_z | RE | 12ms | 20932kb | C++14 | 4.0kb | 2024-07-17 09:33:00 | 2024-07-17 09:33:00 |
Judging History
answer
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
//#pragma GCC optimize("Ofast,fast-math")
//#pragma GCC target("avx,avx2")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
template<typename T> void debug(string s, T x) {
cerr << "[" << s << "] = [" << x << "]\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {
for (int i = 0, b = 0; i < (int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
else if (s[i] == ')' || s[i] == '}') b--;
else if (s[i] == ',' && b == 0) {
cerr << "[" << s.substr(0, i) << "] = [" << x << "] | ";
debug(s.substr(s.find_first_not_of(' ', i + 1)), args...);
break;
}
}
#ifdef ONLINE_JUDGE
#define Debug(...)
#else
#define Debug(...) debug(#__VA_ARGS__, __VA_ARGS__)
#endif
#define pb push_back
#define fi first
#define se second
#define Mry fprintf(stderr, "%.3lf MB\n", (&Med - &Mbe) / 1048576.0)
#define Try cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
typedef long long ll;
// namespace Fread {const int SIZE = 1 << 17; char buf[SIZE], *S, *T; inline char getchar() {if (S == T) {T = (S = buf) + fread(buf, 1, SIZE, stdin); if (S == T) return '\n';} return *S++;}}
// namespace Fwrite {const int SIZE = 1 << 17; char buf[SIZE], *S = buf, *T = buf + SIZE; inline void flush() {fwrite(buf, 1, S - buf, stdout), S = buf;} inline void putchar(char c) {*S++ = c;if (S == T) flush();} struct NTR {~NTR() {flush();}} ztr;}
// #ifdef ONLINE_JUDGE
// #define getchar Fread::getchar
// #define putchar Fwrite::putchar
// #endif
inline int ri() {
int x = 0;
bool t = 0;
char c = getchar();
while (c < '0' || c > '9') t |= c == '-', c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return t ? -x : x;
}
inline void wi(int x) {
if (x < 0) {
putchar('-'), x = -x;
}
if (x > 9) wi(x / 10);
putchar(x % 10 + 48);
}
inline void wi(int x, char s) {
wi(x), putchar(s);
}
bool Mbe;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3f;
const int _ = 1e6 + 5;
int n, m, c[_];
vector<pii> a;
void solve() {
n = ri(), m = ri();
if((n * (n + 1) / 2) % 2 == 0) {
int sum1 = 0, sum2 = 0;
vi b;
int w = n * (n + 1) / 2 / 2;
while(sum1 < n || sum2 < w) {
// [0, n - sum1)
auto p = prev(upper_bound(a.begin() + 0, a.end(), make_pair(w - sum2 - n + sum1 + 1, 0ll)));
b.pb(p->se);
sum1++, sum2 += (p->fi);
}
puts("Yes");
int nw = 0, cnt = 0;
for(int v : b) {
F(j, 1, v) c[++cnt] = nw;
nw ^= 1;
}
F(i, 1, n) {
F(j, 1, m) printf("%d ", c[i]);
printf("\n");
}
} else if((m * (m + 1) / 2) % 2 == 0){
int sum1 = 0, sum2 = 0;
vi b;
int w = m * (m + 1) / 2 / 2;
while(sum1 < m || sum2 < w) {
// [0, n - sum1)
auto p = prev(upper_bound(a.begin() + 0, a.end(), make_pair(w - sum2 - m + sum1 + 1, inf)));
b.pb(p->se);
// Debug(p->se, p->fi, w - sum2 - m + sum1 + 1);
sum1++, sum2 += (p->fi);
}
puts("Yes");
int nw = 0, cnt = 0;
for(int v : b) {
F(j, 1, v) c[++cnt] = nw;
nw ^= 1;
}
F(i, 1, n) {
F(j, 1, m) printf("%d ", c[j]);
printf("\n");
}
} else {
puts("No");
return;
}
}
bool Med;
signed main() {
// Mry;
F(i, 1, 1000001) a.pb({i * (i + 1) / 2, i});
int T = ri();
while(T--) solve();
// Try;
return 0;
}
/*
5 6
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 1 1
0 0 0 0 1 1
[n * m * n * m / 4] = [225]
[chk()] = [225]
3 4
0 0 0 1
0 0 1 1
0 1 1 1
[n * (n + 1) / 2 * m * (m + 1) / 2 / 2] = [30]
[chk()] = [30]
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 20932kb
input:
2 2 3 1 1
output:
Yes 0 1 0 0 1 0 No
result:
ok OK, Accepted. (2 test cases)
Test #2:
score: -100
Runtime Error
input:
5382 1 1 1 2 2 1 1 3 2 2 3 1 1 4 2 3 3 2 4 1 1 5 2 4 3 3 4 2 5 1 1 6 2 5 3 4 4 3 5 2 6 1 1 7 2 6 3 5 4 4 5 3 6 2 7 1 1 8 2 7 3 6 4 5 5 4 6 3 7 2 8 1 1 9 2 8 3 7 4 6 5 5 6 4 7 3 8 2 9 1 1 10 2 9 3 8 4 7 5 6 6 5 7 4 8 3 9 2 10 1 1 11 2 10 3 9 4 8 5 7 6 6 7 5 8 4 9 3 10 2 11 1 1 12 2 11 3 10 4 9 5 8 6 ...