結果

問題 No.800 四平方定理
ユーザー hamrayhamray
提出日時 2019-03-17 22:15:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,487 ms / 2,000 ms
コード長 761 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 73,492 KB
実行使用メモリ 37,632 KB
最終ジャッジ日時 2023-09-22 07:16:01
合計ジャッジ時間 19,308 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,376 KB
testcase_01 AC 16 ms
4,380 KB
testcase_02 AC 11 ms
4,376 KB
testcase_03 AC 13 ms
4,376 KB
testcase_04 AC 12 ms
4,376 KB
testcase_05 AC 14 ms
4,376 KB
testcase_06 AC 18 ms
4,376 KB
testcase_07 AC 19 ms
4,376 KB
testcase_08 AC 12 ms
4,376 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 AC 643 ms
19,936 KB
testcase_11 AC 641 ms
36,444 KB
testcase_12 AC 739 ms
37,444 KB
testcase_13 AC 503 ms
19,872 KB
testcase_14 AC 552 ms
37,076 KB
testcase_15 AC 748 ms
36,580 KB
testcase_16 AC 552 ms
36,124 KB
testcase_17 AC 556 ms
36,196 KB
testcase_18 AC 884 ms
36,120 KB
testcase_19 AC 888 ms
36,028 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 898 ms
36,168 KB
testcase_23 AC 1,487 ms
36,640 KB
testcase_24 AC 1,069 ms
36,068 KB
testcase_25 AC 1,480 ms
36,512 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1,050 ms
36,600 KB
testcase_29 AC 1,299 ms
37,632 KB
testcase_30 AC 1,064 ms
36,136 KB
testcase_31 AC 974 ms
36,872 KB
testcase_32 AC 1,115 ms
36,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <cstring>
#include <functional>
#include <tuple>
using namespace std;
using ll = long long;
vector<ll> v;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll N, D; cin >> N >> D;
    
    for(ll i=1; i<=N; ++i){
        for(ll j=1; j<=N; ++j){
            v.push_back(i*i+j*j);
        }
    }
    sort(v.begin(), v.end());
    
    ll ans=0;
    for(ll i=1; i<=N; ++i){
        for(ll j=1; j<=N; ++j){
            if(D+i*i-j*j<0) break;
            ans += upper_bound(v.begin(), v.end(), D+i*i-j*j) - lower_bound(v.begin(), v.end(), D+i*i-j*j);
        }
    }
    cout << ans << endl;
    
    
    return 0;
}
0