QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#326044#5681. Caravan Trip PlanscryAC ✓0ms3840kbC++202.1kb2024-02-12 08:37:252024-02-12 08:37:27

Judging History

你现在查看的是最新测评结果

  • [2024-02-12 08:37:27]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3840kb
  • [2024-02-12 08:37:25]
  • 提交

answer

#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 0
#else
#include "C:\programmingfunnyxd\debug.cpp"
#endif
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFLL = 1e18;
 
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORE(i,a,b) for(int i = (a); i <= (b); ++i)
#define ROF(i,a,b) for(int i = (a); i >= (b); --i)
#define trav(a,x) for(auto& a: x)
#define sz(x) (int)x.size()
#define make_unique(v) sort(all(v)); v.erase(unique(all(v)), v.end())

template<class T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool ckmin(T& a, const T& b){return b<a?a=b,1:0;}
template<class T> bool ckmax(T& a, const T& b){return a<b?a=b,1:0;}
template<int D, typename T>struct vt : public vector<vt<D - 1, T>> { template<typename... Args>
	vt(int n = 0, Args... args) : vector<vt<D - 1, T>>(n, vt<D - 1, T>(args...)) {}};
template<typename T> struct vt<1, T> : public vector<T> {
	vt(int n = 0, const T& val = T()) : vector<T>(n, val) {}};
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {for(auto &x : a) out << x << ' '; return out;};

const int N = 61;

void solve() {
	int n, q; cin >> n >> q;
	vector<int> oasis(n); cin >> oasis;
	vector<bool> is_oasis(N);
	FOR(i,0,n) is_oasis[oasis[i]] = 1;
	is_oasis[0] = 1;
	vector<vector<ll>> dp(N, vector<ll>(N)); // dp[location][number of days]
	dp[0][0] = 1;
	FOR(i,0,N){
		FOR(j,1,N){
			dp[i][j] = (is_oasis[i] ? dp[i][j - 1] : 0) + (i > 0 ? dp[i - 1][j - 1] : 0);
		}
	}
	//FOR(i,0,N) FOR(j,0,N) debug(i, j, dp[i][j]);
	while(q--){
		int i, t; cin >> i >> t;
		--i;
		debug(oasis[i], t);
		cout << dp[oasis[i]][t] << "\n";
	}
}

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	int t = 1;
	//cin >> t;
	for(int test = 1; test <= t; test++){
		solve();
	}
}

/*   /\_/\
*   (= ._.)
*   / >  \>
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3784kb

input:

5 1
2 3 5 7 11
3 7

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

8 3
2 3 5 7 11 13 17 19
3 7
5 15
8 24

output:

10
126
1287

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

15 5
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
7 23
10 35
4 14
5 23
15 56

output:

1716
8008
330
6188
1307504

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

20 5
3 5 8 10 13 15 18 20 23 25 28 30 33 35 38 40 43 45 48 50
5 23
7 25
13 39
16 50
20 59

output:

3003
3432
27132
5311735
10015005

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

20 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
7 10
3 7
15 20
20 25
11 18

output:

120
35
15504
53130
31824

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

20 5
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
5 15
12 29
8 19
15 40
20 50

output:

252
6188
165
3268760
30045015

result:

ok 5 lines

Test #7:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

20 5
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
20 60
19 60
18 60
17 60
16 60

output:

137846528820
244662670200
353697121050
421171648758
416714805914

result:

ok 5 lines

Test #8:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

20 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 40
20 60
19 60
18 60
17 60
16 60

output:

137846528820
2044802197953900
925029565741050
387221678682300
149608375854525

result:

ok 5 lines

Test #9:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

12 5
2 3 5 7 11 13 17 19 23 29 31 37
2 60
5 60
7 60
9 60
11 60

output:

1711
3162510
99884400
1101716330
2311801440

result:

ok 5 lines

Test #10:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

17 5
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59
12 60
15 60
17 60
13 60
16 60

output:

834451800
37442160
18
347373600
245157

result:

ok 5 lines

Test #11:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

20 5
11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
3 60
5 60
7 60
13 60
16 60

output:

17296
1370754
38320568
5414950296
4059928950

result:

ok 5 lines

Test #12:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

20 5
11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
3 20
5 30
7 40
13 50
16 60

output:

56
4368
346104
37442160
4059928950

result:

ok 5 lines