답안 #9496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
9496 2014-09-28T06:50:59 Z lemonsqueeze Solve another chuck (kriii2_S) C++
1 / 4
24 ms 2492 KB
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int n, m;
int a[101][101];

int tmp[101];
vector<string> ans;

string pjsdream_to_string (long long x)
{
	static char res[12];
	sprintf (res, "%lld", x);
	return res;
}

void rotR (int i, int k)
{
	if (k==0) return;

	ans.push_back ("rotR " + pjsdream_to_string ((long long)i) + " " + pjsdream_to_string ((long long )k));
	for (int j=1; j<=m; j++) tmp[j%m] = a[i][j];
	for (int j=1; j<=m; j++) a[i][j] = tmp[(j-k+m) % m];
}

void rotC (int j, int k)
{
	if (k==0) return;

	ans.push_back ("rotC " + pjsdream_to_string ((long long)j) + " " + pjsdream_to_string ((long long )k));
	for (int i=1; i<=n; i++) tmp[i%n] = a[i][j];
	for (int i=1; i<=n; i++) a[i][j] = tmp[(i-k+n) % n];
}

void negR (int i)
{
	ans.push_back ("negR " + pjsdream_to_string ((long long)i));
	for (int j=1; j<=m; j++) a[i][j] *= -1;
}

void negC (int j)
{
	ans.push_back ("negC " + pjsdream_to_string ((long long)j));
	for (int i=1; i<=n; i++) a[i][j] *= -1;
}

void ricacb (int i, int a, int b)
{
	if (a>b) swap (a, b);

	negC (a);
	rotR (i, m-b+a);
	negC (a);
	rotR (i, b-a);
}

void cirarb (int i, int aa, int b)
{
	if (aa>b) swap (aa, b);

	negR (aa);
	rotC (i, n-b+aa);
	negR (aa);
	rotC (i, b-aa);
}

void ricjracb (int i, int j, int aa, int b)
{
	ricacb (i, b, j);
	cirarb (b, i, aa);
}

void negtopos ()
{
	int li=-1, lj=-1;
	for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) {
		if (a[i][j] < 0) {
			if (li==-1) {
				li = i;
				lj = j;
			}
			else {
				ricjracb (i, j, li, lj);
				li = lj = -1;
			}
		}
	}
}

int main ()
{
	scanf ("%d%d", &n, &m);
	for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) scanf ("%d", &a[i][j]);

	int nc = 0, zc = 0;
	for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) {
		if (a[i][j]<0)
			nc++;
		if (a[i][j]==0)
			zc++;
	}

	if (n%2==0 && m%2==0) {
		negtopos ();

		int ni=-1, nj=-1, nv;
		for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) {
			if (a[i][j]<0) {
				nv = a[i][j];
				ni = i;
				nj = j;
			}
		}

		if (ni!=-1) {
			int pi=-1, pj=-1, pv=100001;
			for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) {
				if (a[i][j]>=0 && pv > a[i][j]) {
					pv = a[i][j];
					pi = i;
					pj = j;
				}
			}

			if (-nv > pv)
				ricjracb (ni, nj, pi, pj);
		}
	}

	else {
		if (nc%2==1) {
			if (n%2==1) negC (1);
			else negR (1);
		}

		negtopos ();
	}

	int s=0;
	for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) s += a[i][j];
	printf ("%d %d\n", s, ans.size ());
	for (int i=0; i<ans.size (); i++)
		printf ("%s\n", ans[i].c_str ());


	// debug
	/*x1`
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++)
			printf ("%d ", a[i][j]);
		printf ("\n");
	}
	*/

	return 0;
}

/*

3 4
1 -2 5 200
-8 0 -4 -10
11 4 0 100

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1284 KB Output is correct
2 Partially correct 0 ms 1284 KB Output is partially correct
3 Partially correct 0 ms 1284 KB Output is partially correct
4 Partially correct 0 ms 1284 KB Output is partially correct
5 Partially correct 0 ms 1284 KB Output is partially correct
6 Partially correct 0 ms 1284 KB Output is partially correct
7 Partially correct 0 ms 1284 KB Output is partially correct
8 Partially correct 4 ms 1572 KB Output is partially correct
9 Partially correct 12 ms 1968 KB Output is partially correct
10 Partially correct 16 ms 2356 KB Output is partially correct
11 Partially correct 12 ms 1968 KB Output is partially correct
12 Partially correct 4 ms 1428 KB Output is partially correct
13 Partially correct 16 ms 1968 KB Output is partially correct
14 Partially correct 16 ms 2100 KB Output is partially correct
15 Partially correct 8 ms 1836 KB Output is partially correct
16 Partially correct 4 ms 1572 KB Output is partially correct
17 Partially correct 0 ms 1284 KB Output is partially correct
18 Partially correct 8 ms 1704 KB Output is partially correct
19 Partially correct 0 ms 1284 KB Output is partially correct
20 Partially correct 24 ms 2492 KB Output is partially correct
21 Partially correct 0 ms 1284 KB Output is partially correct
22 Partially correct 0 ms 1284 KB Output is partially correct
23 Partially correct 12 ms 1968 KB Output is partially correct
24 Partially correct 8 ms 1836 KB Output is partially correct
25 Partially correct 0 ms 1284 KB Output is partially correct
26 Partially correct 8 ms 1572 KB Output is partially correct
27 Partially correct 0 ms 1284 KB Output is partially correct
28 Partially correct 0 ms 1284 KB Output is partially correct
29 Partially correct 8 ms 1572 KB Output is partially correct
30 Partially correct 4 ms 1428 KB Output is partially correct