Submission #70255899


Source Code Expand

#include <bits/stdc++.h>

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define int long long
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int T;

void solve() {
    int C, D;
    cin >> C >> D;
    int ans = 0;
    for (int i = 0; i <= 100000000; ++i) {
        string s = to_string(i * i);
        string s_c = to_string(C);
        int n = s.size();
        int d = s_c.size();
        if (n > d && s.substr(0, d) == s_c) {
            string s_y = s.substr(d, n - d);
            if (s_y.size() == 0 || s_y[0] == '0') {
                continue;
            }
            int y = stoll(s_y);
            if (y > C) {
                int x = y - C;
                if (1 <= x && x <= D) {
                    // cout << "s: " << s << endl;
                    // cout << "s_c: " << s_c << endl;
                    // cout << "y: " << y << endl;
                    // cout << "x: " << x << endl;
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

signed main() {
    cin >> T;
    while (T--) {
        solve();
    }
}

Submission Info

Submission Time
Task D - 183184
User tsuyosshi
Language C++ 20 (gcc 12.2)
Score 0
Code Size 1886 Byte
Status TLE
Exec Time 2759 ms
Memory 3488 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
TLE × 1
TLE × 10
Set Name Test Cases
Sample 00-sample-01.txt
All 00-sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt
Case Name Status Exec Time Memory
00-sample-01.txt TLE 2759 ms 3284 KiB
01-01.txt TLE 2759 ms 3352 KiB
01-02.txt TLE 2759 ms 3324 KiB
01-03.txt TLE 2759 ms 3356 KiB
01-04.txt TLE 2759 ms 3340 KiB
01-05.txt TLE 2759 ms 3304 KiB
01-06.txt TLE 2759 ms 3312 KiB
01-07.txt TLE 2759 ms 3356 KiB
01-08.txt TLE 2759 ms 3488 KiB
01-09.txt TLE 2759 ms 3324 KiB