# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
9445 | ainu7 | Solve another chuck (kriii2_S) | C++98 | 32 ms | 2792 KiB |
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 <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;
int R, C;
vector<string> res;
int arr[100][100];
void rotR(int i) {
char temp[50];
if (C > 1) { sprintf(temp, "rotR %d 1", i+1); res.push_back(temp); }
int t = arr[i][C-1];
for (int k=C-1; k>=1; k--) arr[i][k] = arr[i][k-1];
arr[i][0] = t;
}
void negC() {
char temp[50];
sprintf(temp, "negC 1"); res.push_back(temp);
for (int k=0; k<R; k++) arr[k][0] = -arr[k][0];
}
void rotC() {
char temp[50];
if (R > 1) { sprintf(temp, "rotC 1 1"); res.push_back(temp); }
int t = arr[R-1][0];
for (int k=R-1; k>=1; k--) arr[k][0] = arr[k-1][0];
arr[0][0] = t;
}
void negR() {
char temp[50];
sprintf(temp, "negR 1"); res.push_back(temp);
for (int k=0; k<C; k++) arr[0][k] = -arr[0][k];
}
int main()
{
cin >> R >> C;
for (int i=0; i<R; i++)
for (int j=0; j<C; j++)
cin >> arr[i][j];
for (int i=0; i<R; i++) {
for (int j=0; j<C; j++) {
rotR(i);
if (arr[i][0] < 0) negC();
}
int idx = 0;
for (int j=1; j<C; j++) if (abs(arr[i][j]) < abs(arr[i][idx])) idx = j;
for (int iter=0; iter<C-idx; iter++) rotR(i);
}
int tog = 0;
{
for (int j=0; j<R; j++) {
rotC();
if (arr[0][0] < 0) negR(), tog = 1 - tog;
}
if (tog) {
int idx = 0;
for (int j=1; j<R; j++) if (abs(arr[j][0]) < abs(arr[idx][0])) idx = j;
for (int iter=0; iter<R-idx; iter++) rotC();
negR();
}
}
if (arr[0][0] < 0) {
if (R%2) {
negC();
for (int i=0; i<R-1; i++) {
rotC();
negR();
}
} else if (C%2) {
negR();
for (int i=0; i<C-1; i++) {
rotR(0);
negC();
}
}
}
int r = 0;
for (int i=0; i<R; i++) for (int j=0; j<C; j++) r += arr[i][j];
printf("%d %d\n", r, res.size());
for (int i=0; i<res.size(); i++) cout << res[i] << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |