Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9e0a969

Browse files
Repository has been unarchived
1 parent b99d771 commit 9e0a969

File tree

6 files changed

+519
-0
lines changed

6 files changed

+519
-0
lines changed

‎URI/2878.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Ivan Carvalho
2+
// Solution to https://www.urionlinejudge.com.br/judge/problems/view/2878
3+
#include <bits/stdc++.h>
4+
#define LSOne(S) (S & (-S))
5+
using namespace std;
6+
7+
const int MAXN = 1e5 + 10;
8+
9+
typedef long long ll;
10+
typedef pair<int,int> ii;
11+
12+
vector<ii> myPoints;
13+
vector<int> comp;
14+
int bit[MAXN],N,H,V,X,Y;
15+
16+
void update(int x){
17+
while(x < MAXN){
18+
bit[x]++;
19+
x += LSOne(x);
20+
}
21+
}
22+
23+
int read(int x){
24+
int ans = 0;
25+
while(x > 0){
26+
ans += bit[x];
27+
x -= LSOne(x);
28+
}
29+
return ans;
30+
}
31+
32+
long long invcount(){
33+
34+
memset(bit,0,sizeof(bit));
35+
comp.clear();
36+
N = myPoints.size();
37+
38+
sort(myPoints.begin(),myPoints.end());
39+
40+
for(int i = 0;i<N;i++){
41+
comp.push_back(myPoints[i].second);
42+
}
43+
44+
sort(comp.begin(),comp.end());
45+
46+
long long inversions = 0;
47+
48+
for(int i = 0;i<N;i++){
49+
int val = lower_bound(comp.begin(),comp.end(),myPoints[i].second) - comp.begin() + 1;
50+
inversions += read(N+1) - read(val);
51+
update(val);
52+
}
53+
54+
return inversions;
55+
56+
}
57+
58+
int main(){
59+
60+
cin.tie(0);ios_base::sync_with_stdio(0);
61+
62+
long long ans = 0;
63+
64+
cin >> X >> Y;
65+
cin >> H >> V;
66+
67+
ans += 1LL*(1 + H)*(1 + V);
68+
69+
for(int i = 1;i<=H;i++){
70+
int a,b;
71+
cin >> a >> b;
72+
myPoints.push_back(ii(a,b));
73+
}
74+
75+
ans += invcount();
76+
77+
myPoints.clear();
78+
79+
for(int i = 1;i<=V;i++){
80+
int a,b;
81+
cin >> a >> b;
82+
myPoints.push_back(ii(a,b));
83+
}
84+
85+
ans += invcount();
86+
87+
cout << ans << endl;
88+
89+
return 0;
90+
91+
}
92+

‎URI/2879.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Ivan Carvalho
2+
// Solution to https://www.urionlinejudge.com.br/judge/problems/view/2879
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
int main(){
7+
8+
int N;
9+
cin >> N;
10+
int ans = N;
11+
for(int i = 1;i<=N;i++){
12+
int x;
13+
cin >> x;
14+
if(x == 1) ans--;
15+
}
16+
17+
cout << ans << endl;
18+
19+
return 0;
20+
}

‎URI/2880.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Ivan Carvalho
2+
// Solution to https://www.urionlinejudge.com.br/judge/problems/view/2880
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
string A,B;
7+
8+
int main(){
9+
10+
int matches = 0;
11+
cin >> A >> B;
12+
int N = A.size(), M = B.size();
13+
14+
for(int i = 0;i<N;i++){
15+
if(i + M - 1 >= N) continue;
16+
int delta = 1;
17+
for(int j = 0;j<M;j++){
18+
if(B[j] == A[i + j]){
19+
delta = 0;
20+
break;
21+
}
22+
}
23+
matches += delta;
24+
}
25+
26+
cout << matches << endl;
27+
28+
return 0;
29+
30+
}

‎URI/2881.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Ivan Carvalho
2+
// Solution to
3+
https://www.urionlinejudge.com.br/judge/problems/view/2881
4+
#include <bits/stdc++.h>
5+
using namespace std;
6+
7+
typedef tuple<int,int,int,int> trinca;
8+
9+
const int INF = 1e8;
10+
const int NEG = -INF;
11+
const int MAXL = 1036;
12+
const int MAXN = 1010;
13+
14+
int N,M,dp[MAXN][MAXL],nxt_place[MAXN],stage[MAXN],points[MAXN];
15+
vector<trinca> sortedOrder;
16+
vector<int> mySearch;
17+
18+
int solve(int pos,int bitmask){
19+
20+
if(pos == M){
21+
if(__builtin_popcount(bitmask) != N) return NEG;
22+
return 0;
23+
}
24+
25+
if(dp[pos][bitmask] != -1) return dp[pos][bitmask];
26+
27+
int nxt = nxt_place[pos], nbitmask = bitmask | (1 << stage[pos]);
28+
29+
return dp[pos][bitmask] = max( solve(nxt,nbitmask) + points[pos] ,
30+
solve(pos+1,bitmask) );
31+
32+
}
33+
34+
int main(){
35+
36+
cin >> N;
37+
38+
memset(dp,-1,sizeof(dp));
39+
40+
for(int i = 0;i<N;i++){
41+
int qtd;
42+
cin >> qtd;
43+
for(int j = 0;j<qtd;j++){
44+
int a,b,c;
45+
cin >> a >> b >> c;
46+
sortedOrder.push_back(make_tuple(a,b,c,i));
47+
}
48+
}
49+
50+
M = sortedOrder.size();
51+
sort(sortedOrder.begin(),sortedOrder.end());
52+
53+
for(int i = 0;i<M;i++){
54+
mySearch.push_back(get<0>(sortedOrder[i]));
55+
}
56+
57+
for(int i = 0;i<M;i++){
58+
stage[i] = get<3>(sortedOrder[i]);
59+
points[i] = get<2>(sortedOrder[i]);
60+
vector<int>::iterator it =
61+
lower_bound(mySearch.begin(),mySearch.end(), get<1>(sortedOrder[i]) );
62+
if(it == mySearch.end()){
63+
nxt_place[i] = M;
64+
}
65+
else{
66+
nxt_place[i] = it - mySearch.begin();
67+
}
68+
}
69+
70+
int best = solve(0,0);
71+
if(best < 0) best = -1;
72+
73+
cout << best << endl;
74+
75+
return 0;
76+
77+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /