This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DIM 1010
using namespace std;
int t,n,m,i,j;
int a[DIM][DIM],aux[DIM][DIM],lin[DIM],col[DIM];
vector <pair<int,int> > v;
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>t;
for (;t--;){
memset (a,0,sizeof a);
memset (aux,0,sizeof aux);
memset (lin,0,sizeof lin);
memset (col,0,sizeof col);
cin>>n>>m;
int swapped = 0;
if (n > m){
swap (n,m);
swapped = 1;
}
int sol = m;
for (i=1;i<=n;i++){
/// verific daca am suficiente coloane libere ca sa formez o linie buna
/// nu vreau sa stric coloanele care sunt deja toate ok
v.clear();
for (j=1;j<=m;j++){
if (col[j] + 1 <= (n-1)/2)
v.push_back(make_pair(col[j],j));
}
if (v.size() <= m/2) /// nu mai am cum sa formez nicio linie
break;
sol++;
/// o sa pun unuri pe coloanele unde am cei mai putini
sort (v.begin(),v.end());
for (j=0;j<=m/2;j++){
int poz = v[j].second;
col[poz]++;
lin[i]++;
a[i][poz] = 1;
}
}
if (swapped){
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
aux[m-j+1][i] = a[i][j];
swap (n,m);
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
a[i][j] = 1 - aux[i][j];
}
cout<<sol<<"\n";
for (i=1;i<=n;i++,cout<<"\n")
for (j=1;j<=m;j++){
if (a[i][j])
cout<<"+";
else cout<<"-";
}
}
return 0;
}
Compilation message (stderr)
stones.cpp: In function 'int main()':
stones.cpp:39:26: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
39 | if (v.size() <= m/2) /// nu mai am cum sa formez nicio linie
| ~~~~~~~~~^~~~~~
# | 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... |