답안 #199459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199459 2020-02-01T12:55:14 Z TadijaSebez Jump (BOI06_jump) C++11
100 / 100
27 ms 5624 KB
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int a[N][N],n,m;
bool was[N][N];
struct Number
{
	int c[N];
	void init(){ for(int i=0;i<N;i++) c[i]=0;}
	Number(){ init();}
	void push(){ for(int i=0;i<N-1;i++) c[i+1]+=c[i]/10,c[i]%=10;}
	Number(int x){ init();c[0]=x;push();}
	void print()
	{
		int ptr=N-1;
		while(ptr>0 && c[ptr]==0) ptr--;
		for(int i=ptr;i>=0;i--) printf("%i",c[i]);
		printf("\n");
	}
};
Number operator + (Number a, Number b)
{
	Number ans;
	for(int i=0;i<N;i++) ans.c[i]=a.c[i]+b.c[i];
	ans.push();
	return ans;
}
Number dp[N][N];
Number DP(int x, int y)
{
	if(x==n && y==m) return Number(1);
	if(was[x][y]) return dp[x][y];
	was[x][y]=1;
	if(a[x][y]==0) return dp[x][y]=Number(0);
	dp[x][y].init();
	if(x+a[x][y]<=n) dp[x][y]=dp[x][y]+DP(x+a[x][y],y);
	if(y+a[x][y]<=m) dp[x][y]=dp[x][y]+DP(x,y+a[x][y]);
	//printf("%i %i: ",x,y);
	//dp[x][y].print();
	return dp[x][y];
}
int main()
{
	scanf("%i",&n);
	m=n;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%i",&a[i][j]);
	DP(1,1).print();
	return 0;
}

Compilation message

jump.cpp: In function 'int main()':
jump.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
jump.cpp:46:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%i",&a[i][j]);
                                              ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 4908 KB Output is correct
2 Correct 8 ms 4856 KB Output is correct
3 Correct 8 ms 4856 KB Output is correct
4 Correct 8 ms 4856 KB Output is correct
5 Correct 8 ms 4856 KB Output is correct
6 Correct 8 ms 4984 KB Output is correct
7 Correct 9 ms 4984 KB Output is correct
8 Correct 10 ms 4984 KB Output is correct
9 Correct 10 ms 4984 KB Output is correct
10 Correct 9 ms 4984 KB Output is correct
11 Correct 10 ms 4984 KB Output is correct
12 Correct 10 ms 4984 KB Output is correct
13 Correct 10 ms 4984 KB Output is correct
14 Correct 10 ms 5112 KB Output is correct
15 Correct 14 ms 5216 KB Output is correct
16 Correct 20 ms 5496 KB Output is correct
17 Correct 19 ms 5240 KB Output is correct
18 Correct 24 ms 5496 KB Output is correct
19 Correct 22 ms 5240 KB Output is correct
20 Correct 27 ms 5624 KB Output is correct