結果
問題 | No.491 10^9+1と回文 |
ユーザー |
|
提出日時 | 2017-03-11 00:27:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,007 bytes |
コンパイル時間 | 1,724 ms |
コンパイル使用メモリ | 170,312 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 09:17:49 |
合計ジャッジ時間 | 5,751 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 91 WA * 12 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)#define all(x) (x).begin(),(x).end()#define pb push_back#define fi first#define se secondll n;ll dfs(int digit, string val, int lim){if(digit == (lim+1)/2){string rev=val;reverse(all(rev));string t=val;int r=val.size();if(lim%2==1) --r;for(int i=r-1; i>=0; --i) t+=rev[i];string zeros="";rep(i,9-lim) zeros+='0';string a=t+zeros+t;return atoll(a.c_str())<=n;}ll ret = 0;int l=0;if(digit==0) l=1;for(int i=l; i<10; ++i){char c = '0'+i;ret+=dfs(digit+1,val+c,lim);}return ret;}int main(){cin >>n;ll ans = 0;for(int i=1; i<10; ++i){ans += dfs(0,"",i);}cout << ans << endl;return 0;}