Submission #61394381
Source Code Expand
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define Mikari_My_Wife ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
map<pii,int>mp;
void solve(){
for(int i=2;i<=18;i++){
int sum=0;
int di=i-1;
for(int j=1;j<=9;j++){
int now=1;
for(int lll=0;lll<di;lll++){
now*=j;
}
mp[{i,j}]=now;//len head
sum+=now;
}
}
int l,r;
cin>>l>>r;
string s="",t="";
int lenl=0,lenr=0;
int ll=l,rr=r;
int hl=0,hr=0;
while(ll){
lenl++;
hl=ll%10;
s.push_back(char('0'+ll%10));
ll/=10;
}
while(rr){
lenr++;
t.push_back(char('0'+rr%10));
hr=rr%10;
rr/=10;
}
reverse(s.begin(),s.end());
reverse(t.begin(),t.end());
int ans=0;
if(lenl==lenr){
bool need=1;
for(int i=1;i<lenl;i++){
if(s[i]-'0'>=hl){
need=0;
for(int j=i;j<lenl;j++){
s[j]=char('0'+hl-1);
}
break;
}
}
if(need)ans++;
need=1;
for(int i=1;i<t.size();i++){
if(t[i]-'0'>=hr){
need=0;
for(int j=i;j<t.size();j++){
t[j]=char('0'+hr-1);
}
break;
}
}
if(s!=t)ans++;
for(int i=0;i<lenl;i++){
if(s[i]==t[i]){
continue;
}else {
for(int j=s[i]-'0'+1;j<t[i]-'0';j++){
ans+=mp[{lenl-i,j}];
}
int base=1;
for(int j=i+2;j<lenl;j++){
base*=hl;
}
for(int ii=i+1;ii<lenl;ii++){
for(int jj=hl-1;jj>s[ii]-'0';jj--){
ans+=base;
}
base/=hl;
}
base=1;
int top=hr;
for(int j=i+2;j<lenr;j++){
base*=top;
}
for(int ii=i+1;ii<t.size();ii++){
for(int jj=0;jj<t[ii]-'0';jj++){
ans+=base;
}
base/=top;
}
break;
}
}
}else {
for(int i=lenl+1;i<=lenr-1;i++){
for(int j=1;j<=9;j++)ans+=mp[{i,j}];
}
for(int j=hl+1;j<=9;j++)ans+=mp[{lenl,j}];
for(int j=1;j<=hr-1;j++)ans+=mp[{lenr,j}];
bool need=1;
//------
for(int i=1;i<s.size();i++){
if(s[i]-'0'>=hl){
need=0;
for(int j=i;j<s.size();j++){
s[j]=char('0'+hl-1);
}
break;
}
}
///-------
int base=1;
int top=hl;
for(int i=2;i<s.size();i++){
base*=top;
}
for(int i=1;i<s.size();i++){
for(int jj=top-1;jj>s[i]-'0';jj--){
ans+=base;
}
base/=top;
}
if(need)ans++;
need=1;
for(int i=1;i<t.size();i++){
if(t[i]-'0'>=hr){
need=0;
for(int j=i;j<t.size();j++){
t[j]=char('0'+hr-1);
}
break;
}
}
base=1;
top=hr;
for(int i=2;i<t.size();i++){
base*=top;
}
for(int i=1;i<t.size();i++){
for(int jj=0;jj<t[i]-'0';jj++){
ans+=base;
}
base/=top;
}
ans++;
}
cout<<ans<<endl;
}
signed main(){
//注意多筆測資輸入!!!
Mikari_My_Wife
int t=1;
//cin>>t;
while(t--){solve();}
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Snake Numbers |
| User | zihan_ayame |
| Language | C++ 20 (gcc 12.2) |
| Score | 350 |
| Code Size | 4082 Byte |
| Status | AC |
| Exec Time | 1 ms |
| Memory | 3636 KiB |
Compile Error
Main.cpp: In function ‘void solve()’:
Main.cpp:56:22: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
56 | for(int i=1;i<t.size();i++){
| ~^~~~~~~~~
Main.cpp:59:30: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
59 | for(int j=i;j<t.size();j++){
| ~^~~~~~~~~
Main.cpp:88:34: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
88 | for(int ii=i+1;ii<t.size();ii++){
| ~~^~~~~~~~~
Main.cpp:107:22: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
107 | for(int i=1;i<s.size();i++){
| ~^~~~~~~~~
Main.cpp:110:30: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
110 | for(int j=i;j<s.size();j++){
| ~^~~~~~~~~
Main.cpp:119:22: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
119 | for(int i=2;i<s.size();i++){
| ~^~~~~~~~~
Main.cpp:122:22: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
122 | for(int i=1;i<s.size();i++){
| ~^~~~~~~~~
Main.cpp:132:22: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
132 | for(int i=1;i<t.size();i++){
| ~^~~~~~~~~
Main.cpp:135:30: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
135 | for(int j=i;j<t.size();j++){
| ~^~~~~~~~~
Main.cpp:143:22: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
143 | for(int i=2;i<t.size();i++){
| ~^~~~~~~~~
Main.cpp:146:22: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
146 | for(int i=1;i<t.size();i++){
| ~^~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 04_handmade_00.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3508 KiB |
| 00_sample_01.txt | AC | 1 ms | 3400 KiB |
| 00_sample_02.txt | AC | 1 ms | 3448 KiB |
| 01_random_00.txt | AC | 1 ms | 3516 KiB |
| 01_random_01.txt | AC | 1 ms | 3480 KiB |
| 01_random_02.txt | AC | 1 ms | 3436 KiB |
| 01_random_03.txt | AC | 1 ms | 3504 KiB |
| 01_random_04.txt | AC | 1 ms | 3484 KiB |
| 01_random_05.txt | AC | 1 ms | 3436 KiB |
| 01_random_06.txt | AC | 1 ms | 3512 KiB |
| 01_random_07.txt | AC | 1 ms | 3436 KiB |
| 01_random_08.txt | AC | 1 ms | 3512 KiB |
| 01_random_09.txt | AC | 1 ms | 3452 KiB |
| 02_random2_00.txt | AC | 1 ms | 3560 KiB |
| 02_random2_01.txt | AC | 1 ms | 3564 KiB |
| 02_random2_02.txt | AC | 1 ms | 3488 KiB |
| 02_random2_03.txt | AC | 1 ms | 3504 KiB |
| 03_random3_00.txt | AC | 1 ms | 3448 KiB |
| 03_random3_01.txt | AC | 1 ms | 3332 KiB |
| 03_random3_02.txt | AC | 1 ms | 3564 KiB |
| 03_random3_03.txt | AC | 1 ms | 3636 KiB |
| 03_random3_04.txt | AC | 1 ms | 3436 KiB |
| 04_handmade_00.txt | AC | 1 ms | 3440 KiB |
| 04_handmade_01.txt | AC | 1 ms | 3500 KiB |
| 04_handmade_02.txt | AC | 1 ms | 3480 KiB |
| 04_handmade_03.txt | AC | 1 ms | 3636 KiB |
| 04_handmade_04.txt | AC | 1 ms | 3408 KiB |
| 04_handmade_05.txt | AC | 1 ms | 3488 KiB |
| 04_handmade_06.txt | AC | 1 ms | 3500 KiB |