Submission #22679

# Submission time Handle Problem Language Result Execution time Memory
22679 2017-04-30T06:27:42 Z 삼*전자 그린픽스(#986, pichulia) hi (KRIII5_HI) C++
2 / 7
3 ms 1256 KB
#include<stdio.h>
#define M 1000000007
int n;
int a[109];
int dx[6] = { 1,1,0,-1,-1,0 };
long long int dd[109][109];
int rr[109][109];
long long int dp_small(int p, int q)
{
	int i, j, k;
	if (p < q) { k = p; p = q; q = k; }
	if (q < 0)return 0;
	if (rr[p][q]) return dd[p][q];
	rr[p][q] = 1;
	if (q == 0)return dd[p][q] = p;

	long long int res = 0;
	for (i = 0; i < p; i++) {
		k = i % 6;
		if (dx[k] == 1) {
			res = (res + dp_small(p - i - 1, q)) % M;
		}
		else if (dx[k] == -1) {
			res = (res - dp_small(p - i - 1, q) + M) % M;
		}
	}
	for (i = 0; i < q; i++) {
		k = i % 6;
		if (dx[k] == 1) {
			res = (res + dp_small(q - i - 1, p)) % M;
		}
		else if (dx[k] == -1) {
			res = (res - dp_small(q - i - 1, p) + M) % M;
		}
	}
	return dd[p][q] = res;
}
void process_small() {
	long long int res;
	res = 0;
	int i, j, k;
	int p, q;
	p = a[0];
	q = a[1];
	for (i = 0; i < p; i++) {
		for (j = 0; j <= p - i; j++) {
			k = (i + j) % 6;
			if (dx[k] == 1) {
				res = (res + dp_small(p - (i + j + 1), q)) % M;
			}
			else if (dx[k] == -1) {
				res = (res - dp_small(p - (i + j + 1), q) + M) % M;
			}
		}
	}
	for (i = 0; i < q; i++) {
		for (j = 0; j <= q - i; j++) {
			k = (i + j) % 6;
			if (dx[k] == 1) {
				res = (res + dp_small(q - (i + j + 1), p)) % M;
			}
			else if (dx[k] == -1) {
				res = (res - dp_small(q - (i + j + 1), p) + M) % M;
			}
		}
	}
	printf("%lld\n", res);
}
int main() {
	int i, j, k, l;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (i = 0; i < n; i++) {
		for (j = i+1; j < n; j++) {
			if (a[i] < a[j])
			{
				k = a[i];
				a[i] = a[j];
				a[j] = k;
			}
		}
	}
	if (a[1] == 0) {
		printf("%d\n", a[0]);
		return 0;
	}
	process_small();
	return 0;
}

Compilation message

HI.cpp: In function 'long long int dp_small(int, int)':
HI.cpp:10:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, k;
         ^
HI.cpp: In function 'int main()':
HI.cpp:70:15: warning: unused variable 'l' [-Wunused-variable]
  int i, j, k, l;
               ^
HI.cpp:71:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
HI.cpp:73:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
                     ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1256 KB Output is correct
2 Correct 3 ms 1256 KB Output is correct
3 Correct 3 ms 1256 KB Output is correct
4 Correct 3 ms 1256 KB Output is correct
5 Correct 3 ms 1256 KB Output is correct
6 Correct 3 ms 1256 KB Output is correct
7 Correct 3 ms 1256 KB Output is correct
8 Correct 3 ms 1256 KB Output is correct
9 Correct 3 ms 1256 KB Output is correct
10 Correct 0 ms 1256 KB Output is correct
11 Correct 3 ms 1256 KB Output is correct
12 Correct 3 ms 1256 KB Output is correct
13 Correct 0 ms 1256 KB Output is correct
14 Correct 0 ms 1256 KB Output is correct
15 Correct 0 ms 1256 KB Output is correct
16 Correct 0 ms 1256 KB Output is correct
17 Correct 0 ms 1256 KB Output is correct
18 Correct 0 ms 1256 KB Output is correct
19 Correct 0 ms 1256 KB Output is correct
20 Correct 0 ms 1256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1256 KB Output isn't correct
2 Halted 0 ms 0 KB -