QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#587747 | #6787. Seven Segment Display | piggy123# | WA | 94ms | 3596kb | C++20 | 3.4kb | 2024-09-24 21:25:09 | 2024-09-24 21:25:10 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll cost[16]={6,2,5,5,4,5,6,3,7,6,6,5,4,5,5,4},pw[55];
ll tov(ll w){
if (isdigit(w))return w-'0';
return w-'A'+10;
}
ll dig[8];
ll solve(ll v,ll n){
for (ll i=0;i<8;i++)dig[i]=v/pw[i]%16;
ll rel=0;
ll sm=0;
for (ll j=0;j<16;j++)sm+=cost[j];
for (ll i=0;i<8;i++){
ll lim=pw[i],ss=0;
for (ll j=0;j<i;j++)ss+=dig[j]*pw[j];
ll nd=lim-ss;
ll pn=n;
rel+=min(nd,pn)*cost[dig[i]];
pn-=min(nd,pn);
rel+=pn/pw[i+1]*sm;
pn%=pw[i+1];
for (ll j=(dig[i]+1)%16;j!=dig[i];j=(j+1)%16){
rel+=min(pn,pw[i])*cost[j];
pn-=min(pn,pw[i]);
}
}
return rel;
}
int main(){
ll t;
cin >> t;
pw[0]=1;
for (ll i=1;i<=8;i++)pw[i]=pw[i-1]*16;
ll mx=0;
for (ll i=0;i<8;i++)mx+=pw[i]*15;
while (t--){
ll n;
cin >> n;
string m;
cin >> m;
reverse(m.begin(),m.end());
ll pv=0;
for (ll i=0;i<8;i++)pv+=tov(m[i])*pw[i];
if (pv+n>mx){
ll dif=mx-pv;
cout<< solve(pv,dif+1)+solve(0,n-dif-1)<<"\n";
}else{
cout<< solve(pv,n)<<"\n";
}
}
return 0;
}
/*
■■■■■ ■■ ■■■ ■■■ ■ ■ ■ ■■■■ ■■■■
■ ■■ ■■ ■ ■■ ■ ■■ ■ ■ ■■ ■ ■■ ■■ ■
■ ■ ■■ ■ ■ ■ ■ ■ ■ ■■■ ■■ ■■ ■ ■■
■ ■ ■■ ■ ■ ■ ■ ■ ■ ■■ ■ ■■ ■■
■ ■ ■■ ■ ■ ■■ ■■ ■■ ■
■ ■■ ■■ ■ ■■■ ■ ■■■ ■■ ■■ ■■ ■■■
■■■■■ ■■ ■ ■ ■ ■ ■■ ■■ ■■ ■■
■ ■■ ■ ■ ■ ■ ■■ ■■ ■■ ■
■ ■■ ■ ■ ■ ■ ■■ ■■ ■ ■ ■■
■ ■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ ■■ ■■
■ ■■ ■■■■ ■■■■ ■■ ■■ ■■■■■■ ■■■■
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
3 5 89ABCDEF 3 FFFFFFFF 7 00000000
output:
208 124 327
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 94ms
memory: 3468kb
input:
100000 9364638 AAFC2B35 429015486 47932346 419450064 A2ECB537 658945285 AD0E13E5 34841526 5ABD7876 385322997 E143180D 868762739 1086F8F3 45102799 2F1F9E5E 771587735 CC208792 758215026 9B636EE1 149844 FF4A6462 511247023 D9B7E4D6 453286898 69CB52CE 54578400 3C4F80F1 478112641 EFE86CC5 510676410 CF6EBA...
output:
200848726 5131825367 5364197807 7077985647 527019741 4395682181 8346552656 710528183 8848694605 8979106396 3438999 6257508783 5296421947 831362135 5899915874 6422425192 7310844739 1969926460 6087758323 5964591649 3208748638 8406967170 1071874363 8750416896 8353725389 5582469429 10159207242 106309529...
result:
wrong answer 1st lines differ - expected: '375365926', found: '200848726'