結果

問題 No.152 貯金箱の消失
ユーザー dazydazy
提出日時 2018-06-21 20:41:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 1,216 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 204,840 KB
実行使用メモリ 14,368 KB
最終ジャッジ日時 2023-09-13 07:38:32
合計ジャッジ時間 3,007 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 15 ms
5,148 KB
testcase_08 AC 115 ms
14,172 KB
testcase_09 AC 118 ms
14,368 KB
testcase_10 AC 84 ms
11,892 KB
testcase_11 AC 44 ms
8,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = a; i >= b; i--)
#define fore(i, a) for(auto &i:a)
#define print(x) cout << x << "\n"
#define SORT(a, n) sort(a, a+n);
#define REVERSE(a,n) reverse(a,a+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end());
#define MOD 1000000007
#define yes "YES"
#define no "NO"
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;

int main() {
    fastcin;
    ll l, m = 1, n, t, ans = 0, a, b, c, g;
    cin >> l;
    set<pair<ll, ll> > sp;
    do {
        t = ans;
        n = 2;
        while(1) {
            a = abs(m*m-n*n);
            b = 2*m*n;
            c = m*m + n*n;
            if(4*(a+b+c)>l) break;
            g = gcd(a, b);
            a /= g, b /= g;
            decltype(sp)::iterator it = sp.find(make_pair(a, b));
            if(it==sp.end()) {
                sp.insert(make_pair(a, b));
                ans++;
            }
            n += 2;
        }
        m += 2;
    } while(t!=ans);
    print(ans);
    return 0;
}
0