Submission #796242

# Submission time Handle Problem Language Result Execution time Memory
796242 2023-07-28T08:18:27 Z duyanhloveav Palindrome-Free Numbers (BOI13_numbers) C++17
52.9167 / 100
1000 ms 324 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 "NPAL"
    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);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 16 ms 324 KB Output is correct
4 Incorrect 6 ms 212 KB Output isn't correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Incorrect 6 ms 316 KB Output isn't correct
15 Correct 6 ms 212 KB Output is correct
16 Correct 1 ms 212 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 316 KB Output is correct
20 Correct 6 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 402 ms 296 KB Output is correct
2 Execution timed out 1081 ms 212 KB Time limit exceeded
3 Execution timed out 1077 ms 212 KB Time limit exceeded
4 Execution timed out 1087 ms 212 KB Time limit exceeded
5 Execution timed out 1057 ms 212 KB Time limit exceeded
6 Execution timed out 1079 ms 212 KB Time limit exceeded
7 Correct 165 ms 300 KB Output is correct
8 Correct 122 ms 212 KB Output is correct
9 Correct 226 ms 296 KB Output is correct
10 Correct 305 ms 304 KB Output is correct
11 Correct 381 ms 300 KB Output is correct
12 Execution timed out 1093 ms 212 KB Time limit exceeded
13 Correct 485 ms 300 KB Output is correct
14 Execution timed out 1074 ms 212 KB Time limit exceeded
15 Execution timed out 1083 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 1 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 1083 ms 212 KB Time limit exceeded
22 Correct 1 ms 212 KB Output is correct
23 Execution timed out 1076 ms 212 KB Time limit exceeded
24 Correct 0 ms 212 KB Output is correct
25 Execution timed out 1090 ms 212 KB Time limit exceeded
26 Execution timed out 1078 ms 212 KB Time limit exceeded
27 Execution timed out 1068 ms 212 KB Time limit exceeded
28 Execution timed out 1077 ms 212 KB Time limit exceeded
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Execution timed out 1079 ms 212 KB Time limit exceeded
32 Correct 0 ms 212 KB Output is correct
33 Execution timed out 1071 ms 212 KB Time limit exceeded
34 Correct 1 ms 212 KB Output is correct
35 Execution timed out 1087 ms 212 KB Time limit exceeded
36 Execution timed out 1069 ms 212 KB Time limit exceeded
37 Execution timed out 1084 ms 212 KB Time limit exceeded
38 Execution timed out 1089 ms 212 KB Time limit exceeded
39 Execution timed out 1073 ms 212 KB Time limit exceeded
40 Correct 0 ms 212 KB Output is correct
41 Execution timed out 1085 ms 212 KB Time limit exceeded
42 Correct 0 ms 212 KB Output is correct
43 Execution timed out 1078 ms 212 KB Time limit exceeded
44 Execution timed out 1079 ms 212 KB Time limit exceeded
45 Execution timed out 1080 ms 224 KB Time limit exceeded