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 |
// 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
Your output
16687
System message
Exited with return code 0
Your output
6678
System message
Exited with return code 0
Your output
16687
System message
Exited with return code 0
Your output
6678
System message
Exited with return code 0
Your output
16687
System message
Exited with return code 0
Your output
16687
System message
Exited with return code 0
Your output
6678
System message
Exited with return code 0