이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#ifndef DEBUG
#define d(...)
#else
#define d(...) cerr << "\033[36m" << __VA_ARGS__ << "\033[0m"
#endif
#define R resize
#define EB emplace_back
#define LOG(x) #x << ": " << x
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll a, b;
ll mypow ( int n, int wyk )
{
if ( wyk == 0 )
return 1;
if ( wyk == 1 )
return n;
if ( wyk & 1 )
return (ll)n * mypow( n, wyk - 1 );
ll tmp = mypow( n, wyk / 2 );
return tmp * tmp;
}
ll licz ( int prz, int poz )
{
d( "licz: " << prz << ' ' << poz );
ll res = 1;
if ( prz < 2 and poz )
res *= 9, --poz;
res *= mypow( 8, poz );
d( ' ' << res << ' ' );
return res;
}
ll foo ( ll n )
{
if ( n == -1 )
return 0;
ll res = 1;
string s = to_string( n );
d( s << '\n' );
for ( int i = 1; i <= s.size() - 1; ++i )
res += mypow( 9, min( 2, i ) ) * mypow( 8, max( 0, i - 2 ) );
d( "po pierwszym dodaniu " << res << '\n' );
int i = 0;
for ( ; i < s.size(); ++i )
{
int p = s[i] - '0' - 1;
int il = s[i] - '0';
if ( i == 0 )
--il;
if ( i - 2 >= 0 and s[i - 2] - '0' <= p )
--il;
if ( i - 1 >= 0 and s[i - 1] - '0' <= p )
--il;
d( LOG( i ) << ' ' << LOG( p ) << ' ' << LOG( il ) << '\n' );
ll dod = (ll)il * licz( min( 2, i + 1 ), (int)s.size() - i - 1 );
d( dod << '\n' );
res += dod;
if ( i - 2 >= 0 and s[i - 2] == s[i] )
break;
if ( i - 1 >= 0 and s[i - 1] == s[i] )
break;
}
if ( i == s.size() )
++res;
d( "res na koncu " << res << '\n' );
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> a >> b;
cout << foo( b ) - foo( a - 1 ) << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
ballmachine.cpp: In function 'll foo(ll)':
ballmachine.cpp:49:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for ( int i = 1; i <= s.size() - 1; ++i )
~~^~~~~~~~~~~~~~~
ballmachine.cpp:53:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for ( ; i < s.size(); ++i )
~~^~~~~~~~~~
ballmachine.cpp:72:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if ( i == s.size() )
~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |