Submission #2997084
Source Code Expand
/** * File : D.cpp * Author : Kazune Takahashi * Created : 2018-8-4 21:41:00 * Powered by Visual Studio Code */ #include <iostream> #include <iomanip> // << fixed << setprecision(xxx) #include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ; #include <vector> #include <string> // to_string(nnn) // substr(m, n) // stoi(nnn) #include <complex> #include <tuple> #include <queue> #include <stack> #include <map> // if (M.find(key) != M.end()) { } #include <set> #include <functional> #include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725)); #include <chrono> // std::chrono::system_clock::time_point start_time, end_time; // start = std::chrono::system_clock::now(); // double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count(); #include <cctype> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> using namespace std; #define DEBUG 0 // change 0 -> 1 if we need debug. typedef long long ll; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; // const int C = 1e6+10; int N, M; typedef tuple<int, int> P; vector<P> V[1010][1010]; bool visited[1010][1010]; int rev(int k) { string S = to_string(k); reverse(S.begin(), S.end()); return stoi(S); } void path(int x, int y) { int new_x = x; int new_y = y; if (x < y) { new_x = rev(new_x); } else { new_y = rev(new_y); } if (new_x < new_y) { new_y = new_y - new_x; } else { new_x = new_x - new_y; } V[new_x][new_y].push_back(P(x, y)); } int main() { cin >> N >> M; fill(&visited[0][0], &visited[0][0] + 1010 * 1010, false); for (auto i = 1; i <= 999; i++) { for (auto j = 1; j <= 999; j++) { path(i, j); } } queue<P> Q; for (auto i = 0; i <= 999; i++) { Q.push(P(i, 0)); Q.push(P(0, i)); } Q.push(P(0, 0)); while (!Q.empty()) { int x = get<0>(Q.front()); int y = get<1>(Q.front()); Q.pop(); if (!visited[x][y]) { visited[x][y] = true; for (auto e : V[x][y]) { int new_x = get<0>(e); int new_y = get<1>(e); if (!visited[new_x][new_y]) { Q.push(e); } } } } int ans = 0; for (auto i = 1; i <= N; i++) { for (auto j = 1; j <= M; j++) { if (!visited[i][j]) { ans++; } } } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | D - うほょじご |
User | kazunetakahashi |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 2557 Byte |
Status | AC |
Exec Time | 430 ms |
Memory | 42496 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 | 328 ms | 42496 KB |
02.txt | AC | 326 ms | 42496 KB |
03.txt | AC | 330 ms | 42496 KB |
04.txt | AC | 358 ms | 42496 KB |
05.txt | AC | 330 ms | 42496 KB |
06.txt | AC | 430 ms | 42496 KB |
07.txt | AC | 332 ms | 42496 KB |
08.txt | AC | 330 ms | 42496 KB |
09.txt | AC | 330 ms | 42496 KB |
10.txt | AC | 340 ms | 42496 KB |
11.txt | AC | 348 ms | 42496 KB |
12.txt | AC | 333 ms | 42496 KB |
13.txt | AC | 314 ms | 42496 KB |
14.txt | AC | 310 ms | 42496 KB |
15.txt | AC | 315 ms | 42496 KB |
16.txt | AC | 320 ms | 42496 KB |
s1.txt | AC | 326 ms | 42496 KB |
s2.txt | AC | 340 ms | 42496 KB |
s3.txt | AC | 334 ms | 42496 KB |