QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153801 | #5438. Half Mixed | value0 | WA | 1ms | 3524kb | C++20 | 1.8kb | 2023-08-31 01:08:48 | 2023-08-31 01:08:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n,m,k;
void solve()
{
cin>>n>>m;
ll all = n * (n + 1) / 2 * m * (m + 1) / 2;
if(all & 1)
{
puts("No");
return;
}
ll s,t;
if(n * (n + 1) % 4 == 0)
{
s = n * (n + 1) / 4 - n;
t = n;
}
else if(m * (m + 1) % 4 == 0)
{
s = m * (m + 1) / 4 - m;
t = m;
}
else
{
puts("No");
return;
}
vector<ll> cnt;
while(s)
{
ll a = 1;
while(a * (a - 1) / 2 <= s)
{
a++;
}
a--;
s -= a * (a - 1) /2;
cnt.push_back(a);
t -= a;
// cout<<a<<endl;
}
while(t)
{
cnt.push_back(1);
t--;
}
// while(s)
// {
// ll l = 1;
// ll r = s;
// while(l + 1 < r)
// {
// ll mid = l + r >> 1;
// if(check(mid))
// {
// l = mid;
// }
// else
// {
// r = mid;
// }
// }
// t -= l;
// s -= l * (l + 1) / 2;
// cnt.push_back(l);
// }
vector<vector<int>> g(n + 10,vector<int>(m + 10));
if(n * (n + 1) % 4 == 0)
{
ll cur = 1;
for(int i = 0;i<cnt.size();i++)
{
int len = cnt[i];
for(int j = cur;j < cur + len;j++)
{
for(int k = 1;k<=m;k++)
{
if(i & 1)
{
g[j][k] = 1;
}
else
{
g[j][k] = 0;
}
}
}
cur += len;
}
}
else if(m * (m + 1) % 4 == 0)
{
ll cur = 1;
for(int i = 0;i<cnt.size();i++)
{
int len = cnt[i];
for(int j = cur;j<cur + len;j++)
{
for(int k = 1;k<=n;k++)
{
if(i & 1)
{
g[k][j] = 1;
}
else
{
g[k][j] = 0;
}
}
}
cur += len;
}
}
puts("Yes");
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=m;j++)
{
printf("%d ",g[i][j]);
}
puts("");
}
}
int main()
{
int t = 1;
// cin>>t;
while(t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3524kb
input:
2 2 3 1 1
output:
No
result:
wrong answer Wrong Verdict (test case 1)