Submission #2945618

Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


int rev[1000];
int _rev(int n) {
    // printf("%d ->" , n);
    int x = 0;
    while (n) {
        x = x*10 + (n%10);
        n /= 10;
    }
    // printf(" %d\n", x);
    return x;
}

inline int XY(int x, int y) { return 1000*x + y; }

vector<int> memo(1000000, 0);

ii sim(int x, int y) {
    if (x < y) {
        x = rev[x];
    } else {
        y = rev[y];
    }
    if (x < y) {
        y -= x;
    } else {
        x -= y;
    }
    return ii(x,y);
}

int solve(int N, int M) {
    vector<vector<int> > prev(1000000);
    for (int x=0; x<1000; ++x) {
        for (int y=0; y<1000; ++y) {
            ii p = sim(x,y);
            int here = XY(x,y), there = XY(p.first, p.second);
            // printf("%d %d -> %d %d\n", x,y, p.first,p.second);
            prev[there].pb(here);
        }
    }
    vector<int> visited(1000000, 0);
    queue<int> q;
    // q.push(0);
    for (int x=1; x<=999; ++x) q.push(XY(x,0));
    for (int y=1; y<=999; ++y) q.push(XY(0,y));

    while (!q.empty()) {
        int t = q.front(); q.pop();
        if (visited[t]) continue;
        visited[t] = 1;
        for (int n: prev[t]) {
            q.push(n);
        }
    }
    int cnt = 0;
    for (int x=1; x<=N; ++x) {
        for (int y=1; y<=M; ++y) {
            int k = XY(x,y);
            if (!visited[k]) ++cnt;
        }
    }
    return cnt;
}

int main() {
    rep(i, 1000) rev[i] = _rev(i);

    int N,M; cin>>N>>M;
    cout << solve(N,M) << endl;
    return 0;
}

Submission Info

Submission Time
Task D - うほょじご
User naoya_t
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2756 Byte
Status
Exec Time 113 ms
Memory 45568 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 400 / 400 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 104 ms 45568 KB
02.txt 102 ms 45568 KB
03.txt 105 ms 45568 KB
04.txt 104 ms 45568 KB
05.txt 105 ms 45568 KB
06.txt 102 ms 45568 KB
07.txt 105 ms 45568 KB
08.txt 106 ms 45568 KB
09.txt 106 ms 45568 KB
10.txt 101 ms 45568 KB
11.txt 106 ms 45568 KB
12.txt 108 ms 45568 KB
13.txt 105 ms 45568 KB
14.txt 106 ms 45568 KB
15.txt 104 ms 45568 KB
16.txt 105 ms 45568 KB
s1.txt 113 ms 45568 KB
s2.txt 109 ms 45568 KB
s3.txt 104 ms 45568 KB