답안 #796235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796235 2023-07-28T08:15:16 Z duyanhloveav Palindrome-Free Numbers (BOI13_numbers) C++17
52.9167 / 100
1000 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 9 + 1e6;
const long long oo = 7 + 1e18;

#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

long long pw[20];

string tostring(long long x) {
    string s;
    while (x > 0) {
        s = s + (char)(x % 10 + '0');
        x /= 10;
    }
    reverse(begin(s), end(s));
    return s;
}

void SaKaTa() {
    long long a, b;
    scanf("%lld%lld", &a, &b);
    pw[0] = 1;
    for (int i = 1; i <= 18; i++) {
        pw[i] = pw[i - 1] * 10;
    }
    long long ans = 0;
    // check (s[i], s[i + 1]), (s[i], s[i + 2])
    for (long long i = a; i <= b;) {
        string s = tostring(i);
        s = s + 's';
        long long check = -oo;
        for (int j = 0; j < s.size() - 2; j++) {
            if (s[j] == s[j + 1]) {
                check = s.size() - (j + 1) - 2;
                break;
            }
            else if (s[j] == s[j + 2]) {
                check = s.size() - (j + 2) - 2;
                break;
            }
        }
        if (check == -oo) {
            ++ans;
            check = 0;
        }
        i = (i / pw[check]) * pw[check] + pw[check];
    }
    printf("%lld", ans);
}

int32_t main() {
#define TASKNAME "numbers"
    cin.tie(0)->sync_with_stdio(0);
    if ( fopen( TASKNAME".inp", "r" ) ) {
        freopen (TASKNAME".inp", "r", stdin);
        freopen (TASKNAME".out", "w", stdout);
    }
    int testcase = 1;
//    scanf("%d", &testcase);
    while (testcase--)
        SaKaTa();
    return 0;
}

Compilation message

numbers.cpp: In function 'void SaKaTa()':
numbers.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int j = 0; j < s.size() - 2; j++) {
      |                         ~~^~~~~~~~~~~~~~
numbers.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%lld%lld", &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~
numbers.cpp: In function 'int32_t main()':
numbers.cpp:58:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
numbers.cpp:59:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen (TASKNAME".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 16 ms 328 KB Output is correct
4 Incorrect 9 ms 212 KB Output isn't correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Incorrect 6 ms 212 KB Output isn't correct
15 Correct 6 ms 324 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Incorrect 0 ms 212 KB Output isn't correct
19 Correct 16 ms 212 KB Output is correct
20 Correct 6 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 300 KB Output is correct
2 Execution timed out 1084 ms 212 KB Time limit exceeded
3 Execution timed out 1074 ms 212 KB Time limit exceeded
4 Execution timed out 1069 ms 212 KB Time limit exceeded
5 Execution timed out 1077 ms 212 KB Time limit exceeded
6 Execution timed out 1063 ms 212 KB Time limit exceeded
7 Correct 175 ms 332 KB Output is correct
8 Correct 123 ms 304 KB Output is correct
9 Correct 217 ms 300 KB Output is correct
10 Correct 302 ms 300 KB Output is correct
11 Correct 373 ms 212 KB Output is correct
12 Execution timed out 1086 ms 212 KB Time limit exceeded
13 Correct 462 ms 304 KB Output is correct
14 Execution timed out 1068 ms 212 KB Time limit exceeded
15 Execution timed out 1073 ms 212 KB Time limit exceeded
16 Execution timed out 1071 ms 212 KB Time limit exceeded
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Execution timed out 1085 ms 212 KB Time limit exceeded
22 Correct 1 ms 212 KB Output is correct
23 Execution timed out 1088 ms 212 KB Time limit exceeded
24 Correct 1 ms 324 KB Output is correct
25 Execution timed out 1073 ms 212 KB Time limit exceeded
26 Execution timed out 1081 ms 212 KB Time limit exceeded
27 Execution timed out 1073 ms 212 KB Time limit exceeded
28 Execution timed out 1074 ms 212 KB Time limit exceeded
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Execution timed out 1080 ms 212 KB Time limit exceeded
32 Correct 1 ms 324 KB Output is correct
33 Execution timed out 1063 ms 212 KB Time limit exceeded
34 Correct 1 ms 212 KB Output is correct
35 Execution timed out 1073 ms 212 KB Time limit exceeded
36 Execution timed out 1073 ms 212 KB Time limit exceeded
37 Execution timed out 1068 ms 212 KB Time limit exceeded
38 Execution timed out 1064 ms 212 KB Time limit exceeded
39 Execution timed out 1075 ms 212 KB Time limit exceeded
40 Correct 1 ms 340 KB Output is correct
41 Execution timed out 1061 ms 212 KB Time limit exceeded
42 Correct 0 ms 212 KB Output is correct
43 Execution timed out 1064 ms 212 KB Time limit exceeded
44 Execution timed out 1076 ms 212 KB Time limit exceeded
45 Execution timed out 1068 ms 212 KB Time limit exceeded