이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
char a[1010][1010];
int f[1010] , ok[1010];
priority_queue <pair <int , int> > h;
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int t , n , m , i , j , opt , sol , val , poz;
fscanf (fin,"%d",&t);
for (;t;t--){
fscanf (fin,"%d%d",&n,&m);
if (n >= m){
swap(n , m);
for (i = 1 ; i <= n ; i++){
for (j = 1 ; j <= m ; j++){
a[i][j] = '-';
}
}
opt = n / 2 + 1;
sol = m;
for (i = 1 ; i <= m ; i++){
h.push(make_pair(0 , i));
f[i] = 0;
}
for (i = 1 ; i <= n ; i++){
/// poti sa scoti m / 2 + 1 elem din h a.i toate < opt??
for (j = 1 ; j <= m / 2 + 1 ; j++){
val = -h.top().first;
poz = h.top().second;
h.pop();
if (val + 1 < opt){
ok[j] = poz;
}
else break;
}
if (j > m / 2 + 1){ /// se poate
sol++;
for (j = 1 ; j <= m / 2 + 1 ; j++){
f[ok[j]]++;
h.push(make_pair(-f[ok[j]] , ok[j]));
a[i][ok[j]] = '+';
}
}
}
fprintf (fout,"%d\n" , sol);
for (i = 1 ; i <= m ; i++){
for (j = 1 ; j <= n ; j++){
if (a[i][j] == '+')
a[i][j] = '-';
else a[i][j] = '+';
fputc(a[i][j] , fout);
}
fprintf (fout,"\n");
}
while (!h.empty())
h.pop();
}
else {
for (i = 1 ; i <= n ; i++){
for (j = 1 ; j <= m ; j++){
a[i][j] = '-';
}
}
opt = n / 2 + 1;
sol = m;
for (i = 1 ; i <= m ; i++){
h.push(make_pair(0 , i));
f[i] = 0;
}
for (i = 1 ; i <= n ; i++){
/// poti sa scoti m / 2 + 1 elem din h a.i toate < opt??
for (j = 1 ; j <= m / 2 + 1 ; j++){
val = -h.top().first;
poz = h.top().second;
h.pop();
if (val + 1 < opt){
ok[j] = poz;
}
else break;
}
if (j > m / 2 + 1){ /// se poate
sol++;
for (j = 1 ; j <= m / 2 + 1 ; j++){
f[ok[j]]++;
h.push(make_pair(-f[ok[j]] , ok[j]));
a[i][ok[j]] = '+';
}
}
}
fprintf (fout,"%d\n" , sol);
for (i = 1 ; i <= n ; i++){
for (j = 1 ; j <= m ; j++){
fputc(a[i][j] , fout);
}
fprintf (fout,"\n");
}
while (!h.empty())
h.pop();
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
stones.cpp: In function 'int main()':
stones.cpp:12:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | fscanf (fin,"%d",&t);
| ~~~~~~~^~~~~~~~~~~~~
stones.cpp:15:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | fscanf (fin,"%d%d",&n,&m);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |