Submission ID Problem Status Score Time Memory Code / Answer files User Submit time
#18794 #60. 好對 Good Pair Time Limit Exceeded 11 45014 ms 8184 K C++ 17 / 5.9 K HKSCF2023-057 2023-07-15 16:36:00
Show orginal code
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
#define up(init, end, step) for (ll i = (init); i < (end); i += (step))
#define skip continue
#define stop return EXIT_SUCCESS
#define setup                \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
int main(void) {
    setup;
    // D
    ll n, k, p, ans = 0;
    cin >> n >> k >> p;
    vl v(n);
    up(0, n, 1) v[i] = i + 1;
    do {
        ll res = 0;
        up(0, n - 1, 1) {
            if (v[i + 1] - v[i] == 1) {
                res++;
            }
        }
        if (res == k) {
            ans = (ans + 1) % p;
        }
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << '\n';
    stop;
}
/*
A:
ll n; cin >> n;
    vl v(n);
    for (auto& x : v) {
        cin >> x;
    }
    bitset<21> b;
    unordered_set<ll> s;
    ll cnt = 0;
    while (b.count() <= n) {
        ll sum = 0, val = 1;
        for (ll i = n - 1; i >= 0; i--) {
            if ((cnt & val) > 0) {
                sum += v[i];
            }
            

           // if (b.to_string()[21 + i - n] == '1') {
           //     sum += v[i];
           // }
val <<= 1;
        }
        s.insert(sum);
        cnt++;
        b = bitset<21>(cnt);
    }
    up(1, 2001, 1) {
        if (!s.count(i)) {
            cout << i << '\n';
            return 0;
        }
    }
    cout << 2001 << '\n';
*/
/* B:
    ll n, b1, b2, b4, b6, res = 0; cin >> n >> b1 >> b2 >> b4 >> b6;
    map<ll, ll> m;
    vl v(n); for (auto& x : v) cin >> x, m[x]++;
    sort(v.begin(), v.end(), greater<ll>());
    ll b4Rem = 0, b6Rem = 0, handled = 0;
    //Subtask 1 and 2
    up(0, n, 1) {
        if (v[i] == 1) {
            if (handled) {
                handled--;
                skip;
            }
            if (b1 > 0) b1--,
                res++, m[1]--;
            else if (b2 > 0) b2--,
                res++, m[1]--;
            else if (b4Rem == 1) b4Rem = 0,
                res++, m[1]--;
            else if (b4 > 0) b4--, b4Rem = 1,
                res++, m[1]--;
            else if (b6Rem >= 1) b6Rem--,
                res++, m[1]--;
            else if (b6 > 0) b6--, b6Rem = 2,
                res++, m[1]--;
        }
        else if(v[i] == 2){
            if (b2 >= 1) {
                res += 2;
                b2--;
            }
            else if (b4 >= 1) {
                res+=2;
                b4--;
            }
            else if (b6 > 0) {
                b6--;
                res+=2;
                //Only 2 and 1. 1 and 1 is handled in the first condition
                    if (m[1] >= 1) {
                        m[1]--;
                        res++;
                        handled++;
                    }
            }
        }
        else {
            if (v[i] <= 4) {
                if (b4 > 0) b4--, res += v[i];
                else if (b6 > 0) b6--, res += v[i];
            }
            else {
                if (b6 > 0) b6--, res += v[i];
            }
        }
    }
    cout << res << '\n';*/
/*
* C
    //String must be length 6
    ll n, q; cin >> n >> q;
    vs v(n), g(n); up(0, n, 1) cin >> v[i] >> g[i];
    //Subtask 1, 2  L == R
    while (q--) {
        ll L, R; cin >> L >> R;
        L--, R--;
        ll cor = 0;
        up(0, 6, 1) if (g[L][i] == 'o') cor++;
        sort(v[L].begin(), v[L].end());
        char c = 'a';
        up(0, 6, 1) if (v[L][i] == c) c++;
        if (c == 'f' + 1) {
            if (cor == 0) cout << -1 << '\n';
            else cout << cor << '\n';
        }
        else cout << cor << '\n';
    }*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing
//   code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Subtask #1
Accepted
Score: 11
Test case #1
Accepted
Score: 100
Time: 9 ms
Memory: 368 KiB

Input file

3 1 1000000007

Output file

2

Your output

2

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 9 ms
Memory: 252 KiB

Input file

4 0 1000000007

Output file

11

Your output

11

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 10 ms
Memory: 364 KiB

Input file

1 0 1000000007

Output file

1

Your output

1

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 8 ms
Memory: 244 KiB

Input file

2 0 999984457

Output file

1

Your output

1

System message

Exited with return code 0
Test case #5
Accepted
Score: 100
Time: 10 ms
Memory: 248 KiB

Input file

2 1 999984457

Output file

1

Your output

1

System message

Exited with return code 0
Test case #6
Accepted
Score: 100
Time: 10 ms
Memory: 376 KiB

Input file

8 3 200003539

Output file

1855

Your output

1855

System message

Exited with return code 0
Test case #7
Accepted
Score: 100
Time: 10 ms
Memory: 380 KiB

Input file

8 0 200003539

Output file

16687

Your output

16687

System message

Exited with return code 0
Subtask #2
Time Limit Exceeded
Score: 0
Test case #1
Accepted
Score: 100
Time: 9 ms
Memory: 368 KiB

Input file

3 1 1000000007

Output file

2

Your output

2

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 9 ms
Memory: 252 KiB

Input file

4 0 1000000007

Output file

11

Your output

11

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 10 ms
Memory: 364 KiB

Input file

1 0 1000000007

Output file

1

Your output

1

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 8 ms
Memory: 244 KiB

Input file

2 0 999984457

Output file

1

Your output

1

System message

Exited with return code 0
Test case #5
Accepted
Score: 100
Time: 10 ms
Memory: 248 KiB

Input file

2 1 999984457

Output file

1

Your output

1

System message

Exited with return code 0
Test case #6
Accepted
Score: 100
Time: 10 ms
Memory: 376 KiB

Input file

8 3 200003539

Output file

1855

Your output

1855

System message

Exited with return code 0
Test case #7
Accepted
Score: 100
Time: 10 ms
Memory: 380 KiB

Input file

8 0 200003539

Output file

16687

Your output

16687

System message

Exited with return code 0
Test case #8
Accepted
Score: 100
Time: 55 ms
Memory: 484 KiB

Input file

10 5 999984457

Output file

6678

Your output

6678

System message

Exited with return code 0
Test case #9
Time Limit Exceeded
Score: 0
Time: 1011 ms
Memory: 380 KiB

Input file

12 11 200003539

Output file

1
Test case #10
Time Limit Exceeded
Score: 0
Time: 1053 ms
Memory: 376 KiB

Input file

13 2 200003539

Output file

57271351
Test case #11
Time Limit Exceeded
Score: 0
Time: 1006 ms
Memory: 380 KiB

Input file

13 7 200003539

Output file

244728
Test case #12
Time Limit Exceeded
Score: 0
Time: 1006 ms
Memory: 380 KiB

Input file

14 1 200003539

Output file

70534809
Test case #13
Time Limit Exceeded
Score: 0
Time: 1011 ms
Memory: 252 KiB

Input file

14 2 200003539

Output file

89892172
Subtask #3
Time Limit Exceeded
Score: 0
Test case #1
Accepted
Score: 100
Time: 9 ms
Memory: 368 KiB

Input file

3 1 1000000007

Output file

2

Your output

2

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 9 ms
Memory: 252 KiB

Input file

4 0 1000000007

Output file

11

Your output

11

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 10 ms
Memory: 364 KiB

Input file

1 0 1000000007

Output file

1

Your output

1

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 8 ms
Memory: 244 KiB

Input file

2 0 999984457

Output file

1

Your output

1

System message

Exited with return code 0
Test case #5
Accepted
Score: 100
Time: 10 ms
Memory: 248 KiB

Input file

2 1 999984457

Output file

1

Your output

1

System message

Exited with return code 0
Test case #6
Accepted
Score: 100
Time: 10 ms
Memory: 376 KiB

Input file

8 3 200003539

Output file

1855

Your output

1855

System message

Exited with return code 0
Test case #7
Accepted
Score: 100
Time: 10 ms
Memory: 380 KiB

Input file

8 0 200003539

Output file

16687

Your output

16687

System message

Exited with return code 0
Test case #8
Accepted
Score: 100
Time: 55 ms
Memory: 484 KiB

Input file

10 5 999984457

Output file

6678

Your output

6678

System message

Exited with return code 0
Test case #9
Time Limit Exceeded
Score: 0
Time: 1011 ms
Memory: 380 KiB

Input file

12 11 200003539

Output file

1
Test case #10
Time Limit Exceeded
Score: 0
Time: 1053 ms
Memory: 376 KiB

Input file

13 2 200003539

Output file

57271351
Test case #11
Time Limit Exceeded
Score: 0
Time: 1006 ms
Memory: 380 KiB

Input file

13 7 200003539

Output file

244728
Test case #12
Time Limit Exceeded
Score: 0
Time: 1006 ms
Memory: 380 KiB

Input file

14 1 200003539

Output file

70534809
Test case #13
Time Limit Exceeded
Score: 0
Time: 1011 ms
Memory: 252 KiB

Input file

14 2 200003539

Output file

89892172
Test case #14
Time Limit Exceeded
Score: 0
Time: 1004 ms
Memory: 500 KiB

Input file

15 2 200003539

Output file

93736585
Test case #15
Time Limit Exceeded
Score: 0
Time: 1013 ms
Memory: 252 KiB

Input file

16 8 200003539

Output file

107380845
Test case #16
Time Limit Exceeded
Score: 0
Time: 1007 ms
Memory: 372 KiB

Input file

1767 222 999984457

Output file

445000921
Test case #17
Time Limit Exceeded
Score: 0
Time: 1007 ms
Memory: 632 KiB

Input file

1767 0 999984457

Output file

524100460
Test case #18
Time Limit Exceeded
Score: 0
Time: 1007 ms
Memory: 624 KiB

Input file

2000 0 999984457

Output file

805515441
Test case #19
Time Limit Exceeded
Score: 0
Time: 1008 ms
Memory: 376 KiB

Input file

2000 1999 200003539

Output file

1
Test case #20
Time Limit Exceeded
Score: 0
Time: 1010 ms
Memory: 380 KiB

Input file

2000 1998 200003539

Output file

1999
Subtask #4
Time Limit Exceeded
Score: 0
Test case #1
Accepted
Score: 100
Time: 9 ms
Memory: 252 KiB

Input file

4 0 1000000007

Output file

11

Your output

11

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 10 ms
Memory: 364 KiB

Input file

1 0 1000000007

Output file

1

Your output

1

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 8 ms
Memory: 244 KiB

Input file

2 0 999984457

Output file

1

Your output

1

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 10 ms
Memory: 380 KiB

Input file

8 0 200003539

Output file

16687

Your output

16687

System message

Exited with return code 0
Test case #5
Time Limit Exceeded
Score: 0
Time: 1007 ms
Memory: 632 KiB

Input file

1767 0 999984457

Output file

524100460
Test case #6
Time Limit Exceeded
Score: 0
Time: 1007 ms
Memory: 624 KiB

Input file

2000 0 999984457

Output file

805515441
Test case #7
Time Limit Exceeded
Score: 0
Time: 1009 ms
Memory: 7548 KiB

Input file

925244 0 400001803

Output file

391387012
Test case #8
Time Limit Exceeded
Score: 0
Time: 1008 ms
Memory: 8184 KiB

Input file

1000000 0 400001803

Output file

119141166
Test case #9
Time Limit Exceeded
Score: 0
Time: 1036 ms
Memory: 1144 KiB

Input file

99998 0 999984457

Output file

889257223
Subtask #5
Time Limit Exceeded
Score: 0
Test case #1
Accepted
Score: 100
Time: 9 ms
Memory: 368 KiB

Input file

3 1 1000000007

Output file

2

Your output

2

System message

Exited with return code 0
Test case #2
Accepted
Score: 100
Time: 9 ms
Memory: 252 KiB

Input file

4 0 1000000007

Output file

11

Your output

11

System message

Exited with return code 0
Test case #3
Accepted
Score: 100
Time: 10 ms
Memory: 364 KiB

Input file

1 0 1000000007

Output file

1

Your output

1

System message

Exited with return code 0
Test case #4
Accepted
Score: 100
Time: 8 ms
Memory: 244 KiB

Input file

2 0 999984457

Output file

1

Your output

1

System message

Exited with return code 0
Test case #5
Accepted
Score: 100
Time: 10 ms
Memory: 248 KiB

Input file

2 1 999984457

Output file

1

Your output

1

System message

Exited with return code 0
Test case #6
Accepted
Score: 100
Time: 10 ms
Memory: 376 KiB

Input file

8 3 200003539

Output file

1855

Your output

1855

System message

Exited with return code 0
Test case #7
Accepted
Score: 100
Time: 10 ms
Memory: 380 KiB

Input file

8 0 200003539

Output file

16687

Your output

16687

System message

Exited with return code 0
Test case #8
Accepted
Score: 100
Time: 55 ms
Memory: 484 KiB

Input file

10 5 999984457

Output file

6678

Your output

6678

System message

Exited with return code 0
Test case #9
Time Limit Exceeded
Score: 0
Time: 1011 ms
Memory: 380 KiB

Input file

12 11 200003539

Output file

1
Test case #10
Time Limit Exceeded
Score: 0
Time: 1053 ms
Memory: 376 KiB

Input file

13 2 200003539

Output file

57271351
Test case #11
Time Limit Exceeded
Score: 0
Time: 1006 ms
Memory: 380 KiB

Input file

13 7 200003539

Output file

244728
Test case #12
Time Limit Exceeded
Score: 0
Time: 1006 ms
Memory: 380 KiB

Input file

14 1 200003539

Output file

70534809
Test case #13
Time Limit Exceeded
Score: 0
Time: 1011 ms
Memory: 252 KiB

Input file

14 2 200003539

Output file

89892172
Test case #14
Time Limit Exceeded
Score: 0
Time: 1004 ms
Memory: 500 KiB

Input file

15 2 200003539

Output file

93736585
Test case #15
Time Limit Exceeded
Score: 0
Time: 1013 ms
Memory: 252 KiB

Input file

16 8 200003539

Output file

107380845
Test case #16
Time Limit Exceeded
Score: 0
Time: 1007 ms
Memory: 372 KiB

Input file

1767 222 999984457

Output file

445000921
Test case #17
Time Limit Exceeded
Score: 0
Time: 1007 ms
Memory: 632 KiB

Input file

1767 0 999984457

Output file

524100460
Test case #18
Time Limit Exceeded
Score: 0
Time: 1007 ms
Memory: 624 KiB

Input file

2000 0 999984457

Output file

805515441
Test case #19
Time Limit Exceeded
Score: 0
Time: 1008 ms
Memory: 376 KiB

Input file

2000 1999 200003539

Output file

1
Test case #20
Time Limit Exceeded
Score: 0
Time: 1010 ms
Memory: 380 KiB

Input file

2000 1998 200003539

Output file

1999
Test case #21
Time Limit Exceeded
Score: 0
Time: 1009 ms
Memory: 7548 KiB

Input file

925244 0 400001803

Output file

391387012
Test case #22
Time Limit Exceeded
Score: 0
Time: 1008 ms
Memory: 8184 KiB

Input file

1000000 0 400001803

Output file

119141166
Test case #23
Time Limit Exceeded
Score: 0
Time: 1036 ms
Memory: 1144 KiB

Input file

99998 0 999984457

Output file

889257223
Test case #24
Time Limit Exceeded
Score: 0
Time: 1005 ms
Memory: 2544 KiB

Input file

285226 235325 999984457

Output file

236458440
Test case #25
Time Limit Exceeded
Score: 0
Time: 1009 ms
Memory: 1264 KiB

Input file

124125 53252 999984457

Output file

924923611
Test case #26
Time Limit Exceeded
Score: 0
Time: 1007 ms
Memory: 376 KiB

Input file

3598 11 999984457

Output file

701022665
Test case #27
Time Limit Exceeded
Score: 0
Time: 1009 ms
Memory: 7804 KiB

Input file

952358 43 750001237

Output file

613017908
Test case #28
Time Limit Exceeded
Score: 0
Time: 1007 ms
Memory: 8184 KiB

Input file

1000000 523598 750001237

Output file

68670498
Test case #29
Time Limit Exceeded
Score: 0
Time: 1008 ms
Memory: 8164 KiB

Input file

1000000 666667 750001237

Output file

442044251
Test case #30
Time Limit Exceeded
Score: 0
Time: 1010 ms
Memory: 8176 KiB

Input file

1000000 99998 750001237

Output file

734948807