Skip to content

Commit ba71803

Browse files
committed
round 495 ABCD
1 parent c420a0c commit ba71803

4 files changed

+213
-0
lines changed

1004A. Sonya and Hotels.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <vector>
2+
#include <string>
3+
#include <algorithm>
4+
#include <unordered_set>
5+
#include <numeric>
6+
#include <iostream>
7+
8+
using namespace std;
9+
10+
int main() {
11+
ios::sync_with_stdio(false);
12+
int n, d, x, y, ans=2;
13+
cin >> n >> d >> x;
14+
d <<= 1;
15+
for (int i=1; i<n; ++i) {
16+
cin >> y;
17+
if (y - x > d) ans += 2;
18+
else if (y - x == d) ++ans;
19+
x = y;
20+
}
21+
cout << ans << endl;
22+
23+
return 0;
24+
}

1004B. Sonya and Exhibition.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <vector>
2+
#include <string>
3+
#include <algorithm>
4+
#include <unordered_set>
5+
#include <numeric>
6+
#include <iostream>
7+
8+
using namespace std;
9+
10+
int main() {
11+
ios::sync_with_stdio(false);
12+
int n;
13+
cin >> n;
14+
for (int i=0; i<n; ++i)
15+
cout << (i&1);
16+
cout << endl;
17+
18+
return 0;
19+
}

1004C. Sonya and Robots.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <vector>
2+
#include <string>
3+
#include <algorithm>
4+
#include <unordered_set>
5+
#include <numeric>
6+
#include <iostream>
7+
8+
using namespace std;
9+
10+
int main() {
11+
ios::sync_with_stdio(false);
12+
13+
int n;
14+
cin >> n;
15+
16+
vector<int> a(n+1);
17+
for (int i=1; i<=n; ++i) cin >> a[i];
18+
19+
unordered_set<int> st;
20+
vector<int> s(n+1);
21+
for (int i=1; i<=n; ++i)
22+
if (st.find(a[i])==st.end()) {
23+
++s[i];
24+
st.insert(a[i]);
25+
}
26+
27+
partial_sum(s.begin(), s.end(), s.begin());
28+
29+
st.clear();
30+
long long ans = 0;
31+
for (int i=n; i>0; --i)
32+
if (st.find(a[i])==st.end()) {
33+
ans += s[i-1];
34+
st.insert(a[i]);
35+
}
36+
37+
cout << ans << endl;
38+
return 0;
39+
40+
}

1004D. Sonya and Matrix.cpp

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#include <vector>
2+
#include <string>
3+
#include <algorithm>
4+
#include <unordered_set>
5+
#include <numeric>
6+
#include <iostream>
7+
#include <cstring>
8+
#include <cmath>
9+
10+
using namespace std;
11+
12+
int t;
13+
int a[1000007], b[1000007];
14+
15+
void build(int n, int m, int r, int c, int b[]) {
16+
for (int i=1; i<=n; ++i)
17+
for (int j=1; j<=m; ++j)
18+
++b[abs(i-r)+abs(j-c)];
19+
}
20+
21+
bool ok(int b[]) {
22+
for (int i=0; i<=t; ++i)
23+
if (a[i]!=b[i]) return false;
24+
return true;
25+
}
26+
27+
int main() {
28+
ios::sync_with_stdio(false);
29+
cin >> t;
30+
31+
int mx = 0;
32+
for (int x,i=0; i<t; ++i) {
33+
cin >> x;
34+
mx = max(x, mx);
35+
++a[x];
36+
}
37+
38+
if (t==1) {
39+
if (a[0]==1) {
40+
cout << "1 1\n1 1" << endl;
41+
} else {
42+
cout << -1 << endl;
43+
}
44+
return 0;
45+
}
46+
47+
{
48+
bool line = true;
49+
for (int i=0; i<t; ++i)
50+
if (a[i]!=1) {
51+
line = false;
52+
break;
53+
}
54+
if (line) {
55+
cout << 1 <<' ' << t << "\n1 1" << endl;
56+
return 0;
57+
}
58+
}
59+
60+
int x=-1, y=-1, i, j=0;
61+
for (i=1; a[i] ;++i)
62+
if (a[i]!=i*4) {
63+
if (a[i]+2==i*4) x = i, y = i;
64+
else x = i;
65+
break;
66+
}
67+
68+
if (y==-1) {
69+
for (++i; a[i]==a[i-1]+2;++i);
70+
y = i;
71+
}
72+
73+
// cout << x << ' ' << y << endl;
74+
bool found = false;
75+
76+
if (!(x==-1 || y==-1)) {
77+
// case 1
78+
int c1 = -1, c2 = mx+x+y, c3 = -t;
79+
int delta2 = c2*c2 - 4*c1*c3;
80+
if (delta2>=0 && pow((int)sqrt(delta2), 2)==delta2) {
81+
int delta = sqrt(delta2);
82+
vector<double> ms = {(-c2-delta) / (2.0*c1), (-c2+delta) / (2.0*c1)};
83+
for (auto m : ms)
84+
if (m>0 && m==floor(m) && t%(int)m==0) {
85+
int n = t / m;
86+
memset(b, 0, sizeof(b));
87+
build(n, m, x, y, b);
88+
if (ok(b)) {
89+
found = true;
90+
cout << n << ' ' << m << '\n' << x << ' ' << y << endl;
91+
break;
92+
}
93+
memset(b, 0, sizeof(b));
94+
build(n, m, y, x, b);
95+
if (ok(b)) {
96+
found = true;
97+
cout << n << ' ' << m << '\n' << y << ' ' << x << endl;
98+
break;
99+
}
100+
101+
}
102+
103+
}
104+
105+
// case 2
106+
if (!found) {
107+
int n = x + y - 1;
108+
if (t%n==0) {
109+
if (x<y) swap(x, y);
110+
int m = t / n;
111+
memset(b, 0, sizeof(b));
112+
// printf("%d %d %d %d\n", n,m,x, mx-x+2);
113+
build(n, m, x, (mx-x+2), b);
114+
// for (int i=0; i<=t; ++i)
115+
// cout << b[i] << ' ';cout << endl;
116+
if (ok(b)) {
117+
found = true;
118+
cout << n << ' ' << m << '\n' << x << ' ' << (mx-x+2) << endl;
119+
}
120+
}
121+
}
122+
}
123+
124+
if (!found)
125+
cout << -1 << endl;
126+
127+
128+
return 0;
129+
130+
}

0 commit comments

Comments
 (0)