結果

問題 No.653 E869120 and Lucky Numbers
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-02-23 22:41:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,511 bytes
コンパイル時間 1,164 ms
コンパイル使用メモリ 80,736 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-11 19:22:59
合計ジャッジ時間 2,059 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,356 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

vi mul3(const vi &t){
  int n=t.size();
  vi ret(n);
  int car=0;
  rep(i,n){
    car=car+t[i]*3;
    ret[i]=car%10;
    car/=10;
  }
  if(car!=0)ret.push_back(car);
  return ret;
}
vi add(const vi &t, int k){
  int n=t.size();
  vi ret(n);
  int car=0;
  rep(i,n){
    car=car+t[i];
    if(i==0)car+=k;
    ret[i]=car%10;
    car/=10;
  }
  if(car!=0)ret.push_back(car);
  return ret;
}

vi to_vi(const string &s){
  vi d;
  rep(i,s.length())d.push_back(s[i]-'0');
  reverse(d.begin(),d.end());
  return d;
}

void fail(){
  cout<<"No"<<endl;
  exit(0);
}
void succ(){
  cout<<"Yes"<<endl;
  exit(0);
}

int main(){
  string p;cin>>p;
  vi t=to_vi(p);
  t=mul3(t);
  t=add(t,4);
  if(0){
    for(auto d:t)cerr<<" "<<d;
    cerr<<endl;
  }
  if(t.size()<=1){
    fail();
  }
  if(t[t.size()-1]==4){
    // 0 or 6 ?
    bool ok=1;
    rep(i,t.size()-1){
      if(t[i]%3!=0||t[i]>6)ok=0;
    }
    if(!ok)fail();
    succ();
  }
  if(t[t.size()-1]==2){
    bool ok=1;
    int pos=-1;
    rep(i,t.size()-1){
      if(i==0)continue;
      if(t[i]%3==2){
	if(pos==-1){
	  pos=i;
	}else{
	  fail();
	}
      }
      if(t[i]%3==1||t[i]==9)fail();
    }
    if(pos==-1)fail();
    rep(i,t.size()-2){
      int v=t[i]/3;
      if(i<pos){
	if(v>2)fail();
      }else{
	if(v>1)fail();
      }
    }
    succ();
  }
  fail();
}
0