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 0e5d527

Browse files
Maratona Subregional 2013 completa
1 parent 5f37bc2 commit 0e5d527

File tree

11 files changed

+544
-43
lines changed

11 files changed

+544
-43
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl "\n"
4+
using namespace std;
5+
6+
int main(){
7+
ios::sync_with_stdio(false); cin.tie(NULL);
8+
9+
int a, b, c;
10+
cin >> a >> b >> c;
11+
12+
if(a != b && a != c) cout << "A\n";
13+
else
14+
if(a != b && b != c) cout << "B\n";
15+
else
16+
if(a != c && b != c) cout << "C\n";
17+
else
18+
cout << "*\n";
19+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long int
3+
#define endl '\n'
4+
using namespace std;
5+
6+
struct seg {
7+
int x1, y1, x2, y2, i;
8+
seg(){}
9+
void fix(){
10+
if(x1 < x2) return;
11+
swap(x1, x2);
12+
swap(y1, y2);
13+
}
14+
bool operator<(seg &b){ return max(y1, y2) < max(b.y1, b.y2); }
15+
};
16+
#define pii pair<int, int>
17+
18+
19+
int main(){
20+
ios::sync_with_stdio(false);
21+
cin.tie(0);
22+
23+
int n, m;
24+
cin >> n >> m;
25+
26+
vector<seg> sla(n+m);
27+
28+
for(int i=0; i<n; i++)
29+
{
30+
sla[i].i = i;
31+
cin >> sla[i].x1 >> sla[i].y1 >> sla[i].x2 >> sla[i].y2;
32+
sla[i].fix();
33+
}
34+
35+
for(int j=0; j<m; j++)
36+
{
37+
sla[j+n].i = ~j;
38+
cin >> sla[j+n].x1;
39+
sla[j+n].y1 = 0;
40+
sla[j+n].y2 = -1;
41+
sla[j+n].x2 = sla[j+n].x1;
42+
}
43+
44+
auto orig = sla;
45+
sort(begin(sla), end(sla));
46+
47+
vector<int> aresta(n+m, -1);
48+
set<pii> ativos;
49+
50+
for(auto at : sla)
51+
{
52+
auto [x1, y1, x2, y2, i] = at;
53+
54+
if(i < 0) i = (~i) + n;
55+
56+
auto it = ativos.lower_bound(pii(x1, numeric_limits<int>::min()));
57+
58+
while(it != ativos.end())
59+
{
60+
if(it->first > x2 ) break; //passa direto ou entra?
61+
aresta[it->second] = i;
62+
it = ativos.erase(it);
63+
}
64+
65+
if(y1 == y2) continue;
66+
67+
if(y1 > y2) ativos.insert(pii(x1, i));
68+
else ativos.insert(pii(x2, i));
69+
}
70+
71+
for(auto [x, i] : ativos)
72+
aresta[i] = -2;
73+
74+
vector<int> xend(n+m, -100), yend(n+m, -100);
75+
76+
function<pii(int)> solve = [&](int u){
77+
if(xend[u] != -100) return pii(xend[u], yend[u]);
78+
if(aresta[u] == -1) return pii( -2, orig[u].y1); //flat
79+
if(aresta[u] == -2) return pii( orig[u].y1 > orig[u].y2 ? orig[u].x1 : orig[u].x2 , -1); //inf
80+
81+
auto s = solve(aresta[u]);
82+
if(s.first == -2) s.first = orig[u].y1 > orig[u].y2 ? orig[u].x1 : orig[u].x2;
83+
return s;
84+
};
85+
86+
for(int i=0; i<m ; i++)
87+
{
88+
auto [x, y] = solve(i+n);
89+
cout << x;
90+
if(y > 0) cout << " " << y;
91+
cout << endl;
92+
}
93+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl "\n"
4+
using namespace std;
5+
6+
int main(){
7+
ios::sync_with_stdio(false); cin.tie(NULL);
8+
int n, m, ist;
9+
cin >> n >> m >> ist;
10+
11+
vector<int> age(n);
12+
for(auto &x : age) cin >> x;
13+
14+
vector<vector<int>> g(n);
15+
vector<int> gin(n, 0), roots;
16+
17+
for(int i=0, u, v; i<m; i++){
18+
cin >> u >> v;
19+
u--, v--;
20+
g[u].emplace_back(v);
21+
gin[v]++;
22+
}
23+
vector<int> atual(n);
24+
for(int i=0; i<n; i++) atual[i] = i;
25+
26+
for(int i=0; i<n; i++) roots.emplace_back(i);
27+
28+
vector<int> vis;
29+
function<void(int, int)> dfs = [&](int u, int a){
30+
if(vis[u] <= a) return;
31+
vis[u] = a;
32+
a = min(a, age[u]);
33+
34+
for(auto v : g[u])
35+
dfs(v, a);
36+
};
37+
sort(begin(roots), end(roots), [&](int u, int v){ return age[u] < age[v]; });
38+
39+
auto update = [&](){
40+
vis.assign(n, 1e9+7);
41+
for(auto x : roots) dfs(atual[x], 1e9);
42+
};
43+
update();
44+
45+
char op;
46+
int u, v;
47+
while(ist--)
48+
{
49+
cin >> op;
50+
if(op == 'P'){
51+
cin >> u; u--;
52+
u = atual[u];
53+
if(vis[u] < 1e8) cout << vis[u] << endl;
54+
else cout << "*" << endl;
55+
}
56+
else
57+
{
58+
cin >> u >> v;
59+
u--, v--;
60+
swap(atual[u], atual[v]);
61+
u = atual[u]; v = atual[v];
62+
swap(age[u], age[v]);
63+
update();
64+
}
65+
}
66+
67+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define vi vector<int>
4+
#define endl "\n"
5+
using namespace std;
6+
7+
vector<int> ans;
8+
set<vi> memo;
9+
10+
// ##|###
11+
12+
vi fold(vi &sla, int i){
13+
int n = sla.size();
14+
int m = max(n-i, i);
15+
vi res(m, 0);
16+
17+
if(i+i>=n) // começo é o começo
18+
{
19+
for(int j=0; j<i; j++) res[j] += sla[j];
20+
for(int j=i; j<n; j++) res[j-i] += sla[j];
21+
}
22+
else
23+
{
24+
int d = n-i-i;
25+
for(int j=0; j<i; j++) res[d+j] += sla[j];
26+
for(int j=i; j<n; j++) res[m-j+i-1] += sla[j];
27+
}
28+
29+
return res;
30+
}
31+
32+
bool solve(vector<int> sla){
33+
if(sla == ans) return true;
34+
if(sla.size() < ans.size()) return false;
35+
36+
for(int i=0; i<sla.size(); i++){
37+
vi at = fold(sla, i);
38+
if(memo.count(at)) continue;
39+
memo.insert(at);
40+
if(solve(at)) return true;
41+
}
42+
43+
return false;
44+
}
45+
46+
int main(){
47+
ios::sync_with_stdio(false); cin.tie(NULL);
48+
int n, m;
49+
50+
cin >> n;
51+
vi sla(n);
52+
for(auto &x : sla) cin >> x;
53+
54+
cin >> m;
55+
ans.resize(m);
56+
for(auto &x : ans) cin >> x;
57+
58+
if(accumulate(begin(sla), end(sla), 0LL) != accumulate(begin(ans), end(ans), 0LL)){
59+
cout << "N\n";
60+
return 0;
61+
}
62+
63+
cout << "NS"[solve(sla)] << endl;
64+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main(){
5+
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
6+
int n, m;
7+
cin >> n >> m;
8+
9+
if(n == m){
10+
cout << "*\n";
11+
return 0;
12+
}
13+
14+
vector<bool> p(n+1, false);
15+
16+
for(int i=0, x; i<m; i++){
17+
cin >> x;
18+
p[x] = 1;
19+
}
20+
21+
for(int i=1; i<=n; i++)
22+
if(!p[i])
23+
cout << i << " ";
24+
25+
cout << "\n";
26+
27+
return 0;
28+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl "\n"
4+
using namespace std;
5+
6+
int main(){
7+
ios::sync_with_stdio(false); cin.tie(NULL);
8+
9+
int n;
10+
cin >> n;
11+
12+
vector<int> sla(n+1);
13+
for(int i=1; i<=n; i++) cin >> sla[i], sla[i] += sla[i-1];
14+
15+
int ans = 0;
16+
17+
if(sla.back() % 3){
18+
cout << 0 << endl;
19+
return 0;
20+
}
21+
22+
int lado = sla.back() / 3;
23+
24+
for(int i=0; i<n; i++){
25+
if(sla[i] >= lado) break;
26+
27+
bool ok = true;
28+
29+
auto it = lower_bound(begin(sla), end(sla), sla[i] + lado);
30+
if(it == sla.end() || *it != sla[i] + lado) ok = false;
31+
32+
if(ok) it = lower_bound(begin(sla), end(sla), sla[i] + lado + lado);
33+
if(it == sla.end() || *it != sla[i] + lado + lado) ok = false;
34+
35+
ans += ok;
36+
}
37+
38+
cout << ans << endl;
39+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <bits/stdc++.h>
2+
#define ll long long
3+
#define endl "\n"
4+
using namespace std;
5+
6+
const int MAXN = 305;
7+
int mat[MAXN][MAXN];
8+
int n, m;
9+
10+
void swap_col(int a, int b){
11+
for(int i=0; i<n; i++)
12+
swap(mat[i][a], mat[i][b]);
13+
}
14+
void swap_lin(int a, int b){
15+
for(int j=0; j<m; j++)
16+
swap(mat[a][j], mat[b][j]);
17+
}
18+
19+
int main(){
20+
ios::sync_with_stdio(false); cin.tie(NULL);
21+
22+
cin >> n >> m;
23+
24+
for(int i=0; i<n; i++)
25+
for(int j=0; j<m; j++)
26+
cin >> mat[i][j], mat[i][j]--;
27+
28+
int ans = 0;
29+
30+
for(int i=0; i<n; i++)
31+
while(mat[i][0]/m != i && ans <= (n+m))
32+
swap_lin(i, mat[i][0]/m),
33+
ans++;
34+
35+
for(int j=0; j<m; j++)
36+
while(mat[0][j]%m != j && ans <= (n+m))
37+
swap_col(j, mat[0][j]%m),
38+
ans++;
39+
40+
for(int i=0; i<n; i++)
41+
for(int j=0; j<m; j++)
42+
if(mat[i][j] != i*m + j)
43+
ans = -1;
44+
45+
if(~ans) cout << ans << endl;
46+
else cout << "*\n";
47+
}

0 commit comments

Comments
(0)

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