提出 #67547189


ソースコード 拡げる

#include <bits/stdc++.h>
#define fs first
#define se second
using namespace std;
#define For(s,e)\
  for(int i=s;i<=e;++i)
#define ForR(s,e)\
  for(int i=s;i>=e;--i)
#define FOR(n) \
  for(int i=0;i<n;++i)
#define FORR(n) \
  for(int i=n-1;i>=0;--i)
#define IN(a,n) \
  FOR(n){\
    cin>>a[i];\
  }

unordered_set<long long>s;
bool f(long long x,long long k){
  if(s.count(x)){
    return false;
  }
  s.emplace(x);
  int a[50]={};
  int l=0;
  long long y=x;
  while(x){
    a[l]=x%k;
    x/=k;
    ++l;
  }
  for(int i=0,j=l-1;i<j;++i,--j){
    if(a[i]!=a[j]){
      return false;
    }
  }
  return  true;
}

int main(int /* argc */, char** /* argv */) {
  long long n,k;
  cin>>k>>n;
  int l=0;
  {
    long long x=n;
    while(x){
      x/=10;
      l+=1;
    }
  }
  long long N=n;
  int L=(l/2);
  for(int i=1;i<L;++i){
    N/=10;
  }
  long long ans=0;
  for(long long i=1;i<=N;++i){
    long long l=0;
    long long x=i;
    long long y=0;
    long long z=i;
    long long z2=i/10;
    while(x){
      y*=10;
      y+=x%10;
      x/=10;
      ++l;
      z*=10;
      z2*=10;
    }
    if(z+y<=n){
      if(f(z+y,k)){
        ans+=z+y;
      }
    }
    if(z2+y<=n){
      if(f(z2+y,k)){
        ans+=z2+y;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

提出情報

提出日時
問題 C - Palindromic in Both Bases
ユーザ zz050201010
言語 C++ 23 (Clang 16.0.6)
得点 350
コード長 1348 Byte
結果 AC
実行時間 1297 ms
メモリ 88712 KiB

コンパイルエラー

./Main.cpp:26:13: warning: unused variable 'y' [-Wunused-variable]
  long long y=x;
            ^
./Main.cpp:58:15: warning: variable 'l' set but not used [-Wunused-but-set-variable]
    long long l=0;
              ^
2 warnings generated.

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 350 / 350
結果
AC × 3
AC × 33
セット名 テストケース
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt
ケース名 結果 実行時間 メモリ
00-sample-01.txt AC 2 ms 3504 KiB
00-sample-02.txt AC 1109 ms 88644 KiB
00-sample-03.txt AC 1121 ms 88680 KiB
01-01.txt AC 1 ms 3552 KiB
01-02.txt AC 1 ms 3628 KiB
01-03.txt AC 1297 ms 88588 KiB
01-04.txt AC 1166 ms 88624 KiB
01-05.txt AC 1124 ms 88712 KiB
01-06.txt AC 1133 ms 88672 KiB
01-07.txt AC 1109 ms 88692 KiB
01-08.txt AC 1129 ms 88688 KiB
01-09.txt AC 1192 ms 88648 KiB
01-10.txt AC 1118 ms 88640 KiB
01-11.txt AC 1 ms 3584 KiB
01-12.txt AC 22 ms 8104 KiB
01-13.txt AC 2 ms 3504 KiB
01-14.txt AC 21 ms 8156 KiB
01-15.txt AC 1 ms 3536 KiB
01-16.txt AC 3 ms 3756 KiB
01-17.txt AC 1 ms 3536 KiB
01-18.txt AC 2 ms 3876 KiB
01-19.txt AC 1120 ms 85476 KiB
01-20.txt AC 1 ms 3600 KiB
01-21.txt AC 2 ms 3680 KiB
01-22.txt AC 1 ms 3524 KiB
01-23.txt AC 1 ms 3604 KiB
01-24.txt AC 1 ms 3568 KiB
01-25.txt AC 2 ms 3628 KiB
01-26.txt AC 2 ms 3760 KiB
01-27.txt AC 26 ms 8020 KiB
01-28.txt AC 1 ms 3540 KiB
01-29.txt AC 1 ms 3532 KiB
01-30.txt AC 1 ms 3696 KiB