結果
| 問題 |
No.800 四平方定理
|
| コンテスト | |
| ユーザー |
ttttan
|
| 提出日時 | 2019-03-17 22:49:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 923 bytes |
| コンパイル時間 | 1,238 ms |
| コンパイル使用メモリ | 167,640 KB |
| 実行使用メモリ | 59,852 KB |
| 最終ジャッジ日時 | 2024-07-08 01:14:43 |
| 合計ジャッジ時間 | 9,921 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 2 RE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll’ {aka ‘long long int’} [-Wformat=]
42 | printf("%d\n",ans);
| ~^ ~~~
| | |
| int ll {aka long long int}
| %lld
main.cpp:5:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
5 | int n,d;scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:6:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%d",&d);
| ~~~~~^~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n,d;scanf("%d",&n);
scanf("%d",&d);
map<ll,ll> mp;
vector<ll> v;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++){
if(i*i+d-j*j>0){
v.push_back(i*i+d-j*j);
}
}
}
sort(v.begin(),v.end());
vector<ll> vv=v;
vv.erase(unique(vv.begin(),vv.end()),vv.end());
ll r=vv.size();
ll cnt[r];fill(cnt,cnt+r,0);
ll now=0;
for(ll i=0;i<v.size()-1;i++){
cnt[now]++;
if(v[i]!=v[i+1])now++;
}
cnt[now]++;
v.erase(unique(v.begin(),v.end()),v.end());
ll ans=0;
ll anss=0;
for(ll i=1;i<n;i++){
for(ll j=i;j<=n;j++){
ll y=lower_bound(v.begin(),v.end(),i*i+j*j)-v.begin();
if(v[y]==i*i+j*j){
ans+=cnt[y];
if(i==j)anss+=cnt[y];
}
}
}
ans=ans*2-anss;
printf("%d\n",ans);
}
ttttan