Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <algorithm>
- #include <queue>
- #include <cstdio>
- #include <vector>
- #include <deque>
- #include <map>
- #include <set>
- #include <string>
- #include <deque>
- #include <cmath>
- #include <stack>
- #include <unordered_map>
- #include <cstring>
- #define mp make_pair
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- const ll inf = (long long)1e18;
- const ll mod = 1000 * 1000 * 1000 + 7;
- const int num = 1000 * 1000 + 7;
- const int N = 150000 + 7;
- const long double PI = acos(-1.0);
- struct input {
- int n, m;
- int a[50][50];
- void read() {
- cin >> n >> m;
- for (int i = 1; i <= n; ++i)
- for (int j = 1; j <= m; ++j)
- cin >> a[i][j];
- }
- }ba;
- int syun[50], hor[50];
- int msyun[50], mhor[50];
- int a[50][50];
- int n, m;
- void get() {
- ba.read();
- n = ba.n;
- m = ba.m;
- for (int i = 1; i <= n; ++i)
- for (int j = 1; j <= m; ++j)
- a[i][j] = ba.a[i][j];
- }
- void clear() {
- memset(syun, 0, sizeof(syun));
- memset(hor, 0, sizeof(hor));
- memset(msyun, 0, sizeof(msyun));
- memset(mhor, 0, sizeof(mhor));
- }
- void write() {
- for (int i = 1; i <= n; ++i) {
- for (int j = 1; j < m; ++j) {
- cout << a[i][j] << " ";
- }
- cout << a[i][m] << endl;
- }
- }
- int main() {
- get();
- while (true) {
- clear();
- pair<pair<int,pair<int,int>>, pair<int, int>> as = mp(mp(-10000,mp(-10000,-10000)),mp( 0,0));
- for (int i = 1; i <= n; ++i)
- for (int j = 1; j <= m; ++j) {
- syun[i] += a[i][j];
- hor[j] += a[i][j];
- if (a[i][j] == -1) {
- mhor[j]++;
- msyun[i]++;
- }
- }
- for (int i = 1; i <= n; ++i)
- for (int j = 1; j <= m; ++j) {
- if (a[i][j] == 1) {
- if (as.first.first < min(syun[i], hor[j]))
- as = mp(mp(min(syun[i], hor[j]),mp(max(msyun[i],mhor[j]),min(msyun[i], mhor[j]))),mp(i, j));
- else if (as.first.first == min(syun[i], hor[j])) {
- if (as.first.second.first>max(msyun[i],mhor[j]))
- as = mp(mp(min(syun[i], hor[j]), mp(max(msyun[i], mhor[j]), min(msyun[i], mhor[j]))), mp(i, j));
- else if(as.first.second.first==max(msyun[i], mhor[j])) {
- if (as.first.second.second >min(msyun[i],mhor[j]))
- as = mp(mp(min(syun[i], hor[j]), mp(max(msyun[i], mhor[j]), min(msyun[i], mhor[j]))), mp(i, j));
- }
- }
- }
- }
- if (as.first.first >= 1) {
- a[as.second.first][as.second.second] = -1;
- }
- else {
- write();
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement