Skip to content

Commit 4d5c324

Browse files
authored
Add files via upload
1 parent da0af5a commit 4d5c324

24 files changed

+1843
-0
lines changed

DMOJ/ahardergame.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
const int MAXN = 1e6 + 10;
4+
int N,pilha[MAXN],ptr;
5+
int main(){
6+
scanf("%d",&N);
7+
int tot = 0;
8+
for(int i = 1;i<=N;i++){
9+
ptr++;
10+
scanf("%d",&pilha[ptr]);
11+
tot += pilha[ptr];
12+
while(ptr >= 3 && pilha[ptr - 2] <= pilha[ptr-1] && pilha[ptr-1] >= pilha[ptr]){
13+
pilha[ptr-2] = pilha[ptr - 2] - pilha[ptr - 1] + pilha[ptr];
14+
ptr -= 2;
15+
}
16+
}
17+
int resposta = 0,sinal = 1,ini = 1,fim = ptr;
18+
while(ini<=fim){
19+
if(pilha[ini] >= pilha[fim]){
20+
resposta += sinal*pilha[ini];
21+
ini++;
22+
}
23+
else{
24+
resposta += sinal*pilha[fim];
25+
fim--;
26+
}
27+
sinal *= -1;
28+
}
29+
printf("%d\n",(resposta+tot)/2);
30+
return 0;
31+
}

DMOJ/apio15p1.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
const int MAXN = 2010;
5+
const int MAXM = 110;
6+
int dp[MAXN],N,A,B;
7+
bool tab[MAXM][MAXM],possivel;
8+
ll soma[MAXN],proibido,atual;
9+
ll calc(ll a,ll b){return soma[b] - soma[a-1];}
10+
int solve(int pos){
11+
if(dp[pos] != -1) return dp[pos];
12+
if(pos == N + 1) return dp[pos] = 0;
13+
int best = MAXN;
14+
for(int quebra = pos;quebra<=N;quebra++){
15+
if((calc(pos,quebra)) & proibido) continue;
16+
best = min(best, 1 + solve(quebra+1));
17+
}
18+
return dp[pos] = best;
19+
}
20+
void check(int pos,int resta){
21+
if(possivel) return;
22+
if(tab[pos][resta]) return;
23+
tab[pos][resta] = true;
24+
if(pos == N + 1 && resta == 0) possivel = true;
25+
if(resta == 0 || pos == N+1) return;
26+
for(int quebra = pos;quebra<=N;quebra++){
27+
if((calc(pos,quebra)) & proibido) continue;
28+
check(quebra+1,resta - 1);
29+
}
30+
}
31+
int main(){
32+
cin >> N >> A >> B;
33+
if(A == 1){
34+
for(int i = 1;i<=N;i++){
35+
cin >> soma[i];
36+
soma[i] += soma[i-1];
37+
}
38+
for(ll i = 41;i>=0;i--){
39+
proibido |= (1LL << i);
40+
memset(dp,-1,sizeof(dp));
41+
if(solve(1) > B){
42+
proibido ^= (1LL << i);
43+
atual |= (1LL << i);
44+
}
45+
}
46+
cout << atual << endl;
47+
}
48+
else{
49+
for(int i = 1;i<=N;i++){
50+
cin >> soma[i];
51+
soma[i] += soma[i-1];
52+
}
53+
for(ll i = 37;i>=0;i--){
54+
proibido |= (1LL << i);
55+
memset(tab,false,sizeof(tab));
56+
possivel = false;
57+
for(int j = A;j<=B;j++) check(1,j);
58+
if(!possivel){
59+
proibido ^= (1LL << i);
60+
atual |= (1LL << i);
61+
}
62+
}
63+
cout << atual << endl;
64+
}
65+
return 0;
66+
}

DMOJ/apio16p1.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
const int MAXN = 501;
5+
const ll MOD = 1e9 + 7;
6+
ll dp[MAXN][MAXN],dp2[MAXN][2*MAXN],somatorio1[MAXN],somatorio2[MAXN];
7+
ll precalc[MAXN],A[MAXN],B[MAXN],N,M;
8+
vector<ll> intervalos;
9+
ll binary_expo(ll val,ll pot){
10+
if(pot == 0) return 1LL;
11+
if(pot % 2 == 0){
12+
ll davez = binary_expo(val,pot/2);
13+
return (davez*davez) % MOD;
14+
}
15+
return (val*binary_expo(val,pot-1)) % MOD;
16+
}
17+
int main(){
18+
cin >> N;
19+
for(int i = 1;i<=N;i++){
20+
cin >> A[i] >> B[i];
21+
B[i]++;
22+
intervalos.push_back(A[i]);
23+
intervalos.push_back(B[i]);
24+
}
25+
sort(intervalos.begin(),intervalos.end());
26+
intervalos.erase(unique(intervalos.begin(),intervalos.end()),intervalos.end());
27+
M = intervalos.size() - 2;
28+
ll tot = 0;
29+
for(int v = M;v>=0;v--){
30+
memset(dp,0,sizeof(dp));
31+
memset(somatorio2,0,sizeof(somatorio2));
32+
ll tam = intervalos[v+1] - intervalos[v];
33+
ll vaiate = min(tam,N);
34+
for(ll i = 2;i<=vaiate;i++){
35+
precalc[i] = (tam - i + 1)*binary_expo(i,MOD-2);
36+
precalc[i] %= MOD;
37+
}
38+
for(ll i = N;i>=1;i--){
39+
if(!(A[i] <= intervalos[v] && intervalos[v+1] <= B[i] )) continue;
40+
dp[i][1] = 1;
41+
for(ll j = i+1;j<=N;j++){
42+
dp[i][1] += somatorio1[j];
43+
}
44+
dp[i][1] %= MOD;
45+
dp[i][1] = (dp[i][1] * tam) % MOD;
46+
for(ll k = 2;k<=vaiate;k++){
47+
dp[i][k] = somatorio2[k-1];
48+
}
49+
dp2[i][v] = dp[i][1];
50+
somatorio2[1] += dp[i][1];
51+
somatorio2[1] %= MOD;
52+
for(ll k = 2;k<=vaiate;k++){
53+
dp[i][k] %= MOD;
54+
dp[i][k] *= precalc[k];
55+
dp[i][k] %= MOD;
56+
dp2[i][v] += dp[i][k];
57+
somatorio2[k] += dp[i][k];
58+
somatorio2[k] %= MOD;
59+
}
60+
dp2[i][v] %= MOD;
61+
tot += dp2[i][v];
62+
tot %= MOD;
63+
}
64+
for(int i = 1;i<=N;i++){
65+
somatorio1[i] += dp2[i][v];
66+
somatorio1[i] %= MOD;
67+
}
68+
}
69+
cout << tot << endl;
70+
return 0;
71+
}

DMOJ/boi2007p3.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef pair<int,int> ii;
4+
const int MAXN = 1e6 + 10;
5+
deque<ii> minimo,maximo;
6+
int N,M,C,existe;
7+
int main(){
8+
scanf("%d %d %d",&N,&M,&C);
9+
for(int i = 1;i<M;i++){
10+
int x;
11+
scanf("%d",&x);
12+
ii davez = ii(x,i);
13+
while(!minimo.empty() && minimo.back() > davez) minimo.pop_back();
14+
while(!maximo.empty() && maximo.back() < davez) maximo.pop_back();
15+
minimo.push_back(davez);
16+
maximo.push_back(davez);
17+
}
18+
for(int i = M;i<=N;i++){
19+
int x;
20+
scanf("%d",&x);
21+
ii davez = ii(x,i);
22+
while(!minimo.empty() && minimo.back() > davez) minimo.pop_back();
23+
while(!maximo.empty() && maximo.back() < davez) maximo.pop_back();
24+
minimo.push_back(davez);
25+
maximo.push_back(davez);
26+
if(minimo.front().second == i - M) minimo.pop_front();
27+
if(maximo.front().second == i - M) maximo.pop_front();
28+
if(maximo.front().first - minimo.front().first <= C){
29+
existe++;
30+
printf("%d\n",i - M + 1);
31+
}
32+
}
33+
if(!existe) printf("NONE\n");
34+
return 0;
35+
}

DMOJ/ccoprep16c3q2.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef pair<int,int> ii;
4+
const int MAXN = 2*1e2 + 10;
5+
int N,M;
6+
double gauss[MAXN][MAXN];
7+
vector<ii> grafo[MAXN];
8+
void exibe(){
9+
for(int i = 1;i<=2*N;i++){
10+
for(int j = 1;j<=2*N+1;j++){
11+
printf("%.3lf ",gauss[i][j]);
12+
}
13+
printf("\n");
14+
}
15+
for(int i = 0;i<20;i++) printf("#");
16+
printf("\n");
17+
}
18+
double processa(int pot){
19+
memset(gauss,0,sizeof(gauss));
20+
for(int v = 1;v<=N;v++){
21+
int tam = grafo[v].size();
22+
double inverso = 1.0/double(max(tam,1));
23+
gauss[v][v] += 1.0;
24+
gauss[v+N][v+N] += 1.0;
25+
if(v == N) continue;
26+
for(int i = 0;i<grafo[v].size();i++){
27+
int u = grafo[v][i].first;
28+
int peso = (grafo[v][i].second & ( 1 << pot)) ? (1) : (0);
29+
if(peso == 0){
30+
gauss[v][u] += -inverso;
31+
gauss[v+N][u+N] += -inverso;
32+
}
33+
else{
34+
gauss[v][u+N] += -inverso;
35+
gauss[v+N][u] += -inverso;
36+
}
37+
}
38+
}
39+
//exibe();
40+
gauss[2*N][2*N+1] += 1.0;
41+
for(int linha = 2*N;linha>=1;linha--){
42+
for(int nxtlinha = 1;nxtlinha<linha;nxtlinha++){
43+
double razao = gauss[nxtlinha][linha]/gauss[linha][linha];
44+
for(int coluna = 1;coluna<=2*N+1;coluna++){
45+
gauss[nxtlinha][coluna] -= razao*gauss[linha][coluna];
46+
}
47+
}
48+
//exibe();
49+
}
50+
return gauss[1][2*N+1]/gauss[1][1];
51+
}
52+
int main(){
53+
double expected = 0;
54+
cin >> N >> M;
55+
for(int i = 1;i<=M;i++){
56+
int u,v,w;
57+
cin >> u >> v >> w;
58+
grafo[u].push_back(ii(v,w));
59+
if(u != v) grafo[v].push_back(ii(u,w));
60+
}
61+
for(int pot = 0;pot<=30;pot++){
62+
expected += processa(pot)*((1 << pot));
63+
}
64+
printf("%.3lf\n",expected);
65+
return 0;
66+
}

DMOJ/coci15c2p4.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef pair<char,char> dupla;
4+
map<dupla,int> vazio;
5+
vector<map<dupla,int> > Trie;
6+
vector<int> fim,qtd;
7+
int N,TriePtr;
8+
9+
int main(){
10+
fim.push_back(0);
11+
qtd.push_back(0);
12+
Trie.push_back(vazio);
13+
cin >> N;
14+
int best = 0;
15+
for(int palavra = 1;palavra<=N;palavra++){
16+
string s;
17+
cin >> s;
18+
int melhor = 1;
19+
int atual = 0;
20+
for(int i = 0, j = s.size()-1;j>=0;i++,j--){
21+
if(fim[atual]) melhor = max(melhor,qtd[atual]+1);
22+
dupla davez = dupla(s[i],s[j]);
23+
if(Trie[atual].count(davez)){
24+
atual = Trie[atual][davez];
25+
}
26+
else{
27+
break;
28+
}
29+
}
30+
if(fim[atual]) melhor = max(melhor,qtd[atual]+1);
31+
best = max(best,melhor);
32+
atual = 0;
33+
for(int i = 0, j = s.size()-1;j>=0;i++,j--){
34+
dupla davez = dupla(s[i],s[j]);
35+
if(Trie[atual].count(davez)){
36+
atual = Trie[atual][davez];
37+
}
38+
else{
39+
Trie[atual][davez] = ++TriePtr;
40+
fim.push_back(0);
41+
qtd.push_back(0);
42+
Trie.push_back(vazio);
43+
atual = TriePtr;
44+
}
45+
}
46+
fim[atual] = 1;
47+
qtd[atual] = max(qtd[atual],melhor);
48+
}
49+
cout << best << endl;
50+
return 0;
51+
}

0 commit comments

Comments
 (0)