Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Ynng committed Mar 28, 2021
1 parent e52fe8e commit 540e897
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/ipch
a.exe
a.out
.history
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"Local: devices","url":"f:\\GitHub\\Practice\\Olympiad Practise\\week 33\\devices.cpp","tests":[{"id":1616872340528,"input":"5\n1 2 3 2 1\n1\n3","output":"2"},{"id":1616872753362,"input":"5\n1 2 5 5 4\n4\n1\n5\n3\n4","output":"1\n1\n1\n2"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"f:\\GitHub\\Practice\\Olympiad Practise\\week 33\\devices.cpp","group":"local","local":true}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"Local: orzbruce4","url":"f:\\GitHub\\Practice\\Olympiad Practise\\week 33\\orzbruce4.cpp","tests":[{"id":1616870541020,"input":"4 4 1\n1 4\n1 2\n1 3\n4 2","output":"2"},{"id":1616870546543,"input":"10 6 2\n1 2\n2 10\n4 8\n8 10\n5 7\n2 4","output":"4"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"f:\\GitHub\\Practice\\Olympiad Practise\\week 33\\orzbruce4.cpp","group":"local","local":true}
Binary file added Olympiad Practise/week 33/devices.bin
Binary file not shown.
88 changes: 88 additions & 0 deletions Olympiad Practise/week 33/devices.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define sz(x) (int)(x).size()
#define ms(x, y) memset(x, y, sizeof(x))
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const int MOD = 1000000007, MX = 100000 + 5;

int N, A[MX], D;
int freq[MX];

ll f[MX]; //factorial
ll inv[MX];

//quick power
ll quickpow(ll base, ll exp)
{
ll ans = 1;
for (base %= MOD; exp; exp >>= 1, base = (base * base) % MOD)
if (exp & 1)
ans = (ans * base) % MOD;
return ans;
}

//nChoosek nck choosing notation
ll choose(int n, int k)
{
return f[n] * inv[k] % MOD * inv[n - k] % MOD;
}

//initializing choosing notation and factorial etc
void init(int N)
{
f[0] = 1;
inv[0] = 1;
for (int i = 1; i <= N + 5; i++)
f[i] = f[i - 1] * i % MOD;
for (int i = 1; i <= N + 5; i++)
inv[i] = quickpow(f[i], MOD - 2);
}

int main()
{
scanf("%d", &N);
init(N);

for (int i = 1; i <= N; i++)
{
scanf("%d", A + i);
freq[A[i]]++;
}
sort(A + 1, A + 1 + N);
for (int i = 1; i <= N; i++)
freq[i] += freq[i - 1];

scanf("%d", &D);
for (int i = 1, k; i <= D; i++)
{
scanf("%d", &k);
int p = A[k];
int need = k - freq[p - 1], tot = freq[p] - freq[p - 1];
printf("%lld\n", choose(tot, need));
}

return 0;
}
Binary file added Olympiad Practise/week 33/orzbruce4.bin
Binary file not shown.
93 changes: 93 additions & 0 deletions Olympiad Practise/week 33/orzbruce4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define INF 0x3f3f3f3f // for int
#define LL_INF 0x3f3f3f3f3f3f3f3f // for ll
#define sz(x) (int)(x).size()
#define ms(x, y) memset(x, y, sizeof(x))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const int MOD = 1000000007, MX = 200000 + 5;

int N, M, K;
vector<int> G[MX];
int dist1[MX], distN[MX];

//quick power
ll quickpow(ll base, ll exp)
{
ll ans = 1;
for (base %= MOD; exp; exp >>= 1, base = (base * base) % MOD)
if (exp & 1)
ans = (ans * base) % MOD;
return ans;
}

int main()
{
scanf("%d %d %d", &N, &M, &K);
for (int i = 1, a, b; i <= M; i++)
{
scanf("%d %d", &a, &b);
G[a].push_back(b);
G[b].push_back(a);
}

queue<pi> q;
q.push({1,0});
dist1[1]=-1;
while(!q.empty()){
for(int n : G[q.front().f]){
if(dist1[n])continue;
dist1[n] = q.front().s+1;
q.push({n, dist1[n]});
}
q.pop();
}

q.push({N,0});
distN[N]=-1;
while(!q.empty()){
for(int n : G[q.front().f]){
if(distN[n])continue;
distN[n] = q.front().s+1;
q.push({n, distN[n]});
}
q.pop();
}

ll num = 0;

for(int i = 1; i <= N; i++)
{
// printf("%d: %d %d\n", i, dist1[i], distN[i]);
if(dist1[i]<=0 || distN[i] <= 0)continue;
// printf("yes\n");
if(dist1[i] <= K && distN[i] <= K)num++;
}


printf("%lld\n", quickpow(2, num));
return 0;
}
Binary file removed a.out
Binary file not shown.
Binary file removed b.exe
Binary file not shown.

0 comments on commit 540e897

Please sign in to comment.