Submission #2944821
Source Code Expand
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
return a.second < b.second;
}
map<P , bool> mp;
int dp[1000][1000];
int rev(int x){
char s[10] = "",v[10]="";
sprintf(s,"%d",x);
for(int i=0;i<strlen(s);i++){
v[strlen(s)-i-1] = s[i];
}
return atoi(v);
}
bool DP(int x,int y){
if(dp[x][y] != -1)
return dp[x][y];
else if(dp[x][y] == 0 || x == 0 || y == 0)
return dp[x][y] = 0;
if(mp[P(x,y)] == true || mp[P(y,x)] == true){
dp[y][x] = 1;
return dp[x][y] = 1;
}else{
mp[P(x,y)] = true;
int nx,ny;
if(x > y){
ny = rev(y);
nx = x;
}else{
nx = rev(x);
ny = y;
}
if(nx > ny)
return dp[x][y] = DP(nx-ny,ny);
else
return dp[x][y] = DP(nx,ny-nx);
}
}
int main()
{
int cnt=0,N,M;
REP(i,1000)REP(j,1000)dp[i][j] = -1;
REP(i,1000){
dp[i][0] = 0;
dp[0][i] = 0;
}
cin >> N >> M;
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++){
mp.clear();
DP(i,j);
if(dp[i][j] == 1)
cnt++;
}
cout << cnt << endl;
return 0;
}
int par[MAX_N];
int ranks[MAX_N];
//n要素で初期化
void init(int n){
REP(i,n){
par[i] = i;
ranks[i] = 0;
}
}
//木の根を求める
int find(int x){
if(par[x] == x){
return x;
}else{
return par[x] = find(par[x]);
}
}
void unite(int x,int y){
x = find(x);
y = find(y);
if(x == y) return ;
if(ranks[x] < ranks[y]){
par[x] = y;
}else{
par[y] = x;
if(ranks[x] == ranks[y]) ranks[x]++;
}
}
bool same(int x, int y){
return find(x) == find(y);
}
Submission Info
Submission Time |
|
Task |
D - うほょじご |
User |
makss |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2142 Byte |
Status |
AC |
Exec Time |
256 ms |
Memory |
4224 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt, s3.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, s1.txt, s2.txt, s3.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
256 ms |
4224 KB |
02.txt |
AC |
3 ms |
4096 KB |
03.txt |
AC |
161 ms |
4224 KB |
04.txt |
AC |
6 ms |
4224 KB |
05.txt |
AC |
6 ms |
4224 KB |
06.txt |
AC |
3 ms |
4096 KB |
07.txt |
AC |
3 ms |
4096 KB |
08.txt |
AC |
248 ms |
4224 KB |
09.txt |
AC |
11 ms |
4096 KB |
10.txt |
AC |
206 ms |
4224 KB |
11.txt |
AC |
251 ms |
4224 KB |
12.txt |
AC |
4 ms |
4096 KB |
13.txt |
AC |
4 ms |
4096 KB |
14.txt |
AC |
80 ms |
4224 KB |
15.txt |
AC |
3 ms |
4096 KB |
16.txt |
AC |
104 ms |
4224 KB |
s1.txt |
AC |
3 ms |
4096 KB |
s2.txt |
AC |
4 ms |
4096 KB |
s3.txt |
AC |
30 ms |
4224 KB |