結果

問題 No.2190 平方数の下12桁
ユーザー ttkkggwwttkkggww
提出日時 2023-01-13 22:14:51
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,033 bytes
コンパイル時間 4,787 ms
コンパイル使用メモリ 265,656 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 17:51:52
合計ジャッジ時間 6,300 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:12: warning: built-in function 'pow10' declared as non-function [-Wbuiltin-declaration-mismatch]
    9 | vector<ll> pow10;
      |            ^~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
string s;
vector<ll> pow2[] = {{0},{1,9},{},{},{2,8},{5},{4,6},{},{},{3,7}};
ll n;
vector<ll> pow10;
bool is = false;

void dfs(ll cur,vector<ll> ans,ll depth){
	if(depth==n){
		reverse(ans.begin(),ans.end());
		//for(auto &i:ans)cout<<i;cout<<endl;
		if(cur%pow10[depth]==0){
			is = true;
		}
		return;
	}
	for(auto &i:{0,1,2,3,4,5,6,7,8,9}){
		ll nx = cur;
		for(int j = 0;j<ans.size();j++){
			if(depth+j<=n)
			nx -= pow10[depth+j]*ans[j]*i*2;
		}
		nx -= pow10[depth*2]*i*i;
		//cout<<nx/pow10[depth]<<' '<<i<<endl;
		ans.push_back(i);
		if(nx%pow10[depth+1]==0){
			dfs(nx,ans,depth+1);
		}
		ans.pop_back();
	}
}

ll INF = 1e18;
void solve(){
	{
		ll cur = 1;
		for(int i = 0;i<19;i++){
			pow10.push_back(cur);
			cur*=10;
		}
	}
	n = s.size();
	dfs(stoll(s)+INF,{},0);
	if(is)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> s;
	solve();
}
0