Skip to content

Commit 3f3ca8b

Browse files
committed
df
1 parent a0872b3 commit 3f3ca8b

10 files changed

+643
-19
lines changed

199d.cpp

+12-19
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ using namespace std;
6767

6868
const long long INF = 1e18;
6969
const long long MAX = 2e5+10;
70-
vector<int>adj[20];
70+
vector<int>adj[30];
7171
vector<int>vis(30,0);
7272
vector<int>d;
7373
void dfs(int i){
@@ -77,26 +77,19 @@ void dfs(int i){
7777
for(auto j : adj[i])
7878
dfs(j);
7979
}
80-
void dfs(int i, LL &n, vector<int>&c, int cnt=0){
81-
if(c[i] != -1) return;
82-
cnt++;
80+
void dfs(int i,LL &n, vector<int>&c){
81+
if(i == d.size()) {n++; return;}
82+
if(c[d[i]] != -1) return;
8383
FOR(col,1,4){
84-
c[i] = col;
84+
c[d[i]] = col;
8585
bool ok = true;
86-
for(auto j : adj[i]){
86+
for(auto j : adj[d[i]])
8787
if(c[j] == col) ok = false;
88-
}
89-
for(auto j : adj[i]){
90-
if(ok) dfs(j,n,c,cnt);
91-
}
92-
if(ok && cnt==d.size()) {
93-
cout<<col<<"***"<<i<<"////";
94-
for (auto k : d) cout<<c[k]<<"; ";
95-
cout<<endl;
96-
n++;
97-
}
88+
89+
if(!ok) continue;
90+
dfs(i+1,n,c);
9891
}
99-
c[i] = -1;
92+
c[d[i]] = -1;
10093
}
10194
int main(){
10295
fastio;
@@ -113,9 +106,9 @@ int main(){
113106
if(vis[i]) continue;
114107
LL cnt=0;
115108
d.clear();
116-
vector<int>col(20,-1);
109+
vector<int>col(30,-1);
117110
dfs(i);
118-
dfs(i,cnt,col);
111+
dfs(0,cnt,col);
119112
ans *= cnt;
120113
}
121114
cout<<ans;

206.cpp

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/* |\ | | ||\ \ /(_~ |~)|_~|\/||_~|\/||~)|_~|~)
2+
|~\|_|/\||~\ | ,_) |~\|__| ||__| ||_)|__|~\
3+
4+
\ //~\| | |\ |~)|_~ | ||\ ||/~\| ||_~
5+
| \_/\_/ |~\|~\|__ \_/| \||\_X\_/|__
6+
(J U S T L I K E E V E R Y O N E E L S E !)
7+
8+
__ ,..---.._
9+
+''''`--''-..`--..__
10+
.\ _,/:i--._`:-:+._`.``-._
11+
/`.._,,' \ `-.``--:.b....=.
12+
|`..__,,..`. '`.__::i--.-::_
13+
)- .....--i'\.. --+`'''-'
14+
,' .'.._,.-'|._-b\
15+
/,'<' V `oi| \ _.
16+
|/ -|,--.." ,'-. ||\.. _.,;:'_<'
17+
''/ | . ' |\||'\ /-'_/' `.
18+
|,','| , . .-.|:.`. + .,:.. |
19+
._,:'/ /-\ '^' -Y"\ |.| || /,+8d| |
20+
.|/,'| |/':: ':=:' ,'| | | \|| "+)=' |
21+
|+,';' /|_/ \ _/ \b':.\ \'| .|| ,'
22+
,,:-i''_i' | ``-.Y',. ,|`: | \;- | |_,'
23+
__ |'| |i:'._ ,' ,' ,; | |-)-' __--:b__
24+
.P| | |/,'|\ - ._ / / _,Y- ,:/' `. `'".._
25+
,'|| -','' | ._i._ `':| ,..,' ,Y;' \ `- ._
26+
|||||,.. | \ '-.._ _,' / _,b-' `. '-.
27+
||||P..i, .| '....,-' _,'''''-''' ' _,.. `\
28+
+'` <'/ |`-.....---' ._ ,._
29+
| | ,'``,:-''''/,--`.
30+
Y|.b_,,: | || ,;,Y' / |.
31+
,' /'----' .'| .. | | '" .`Y' .,-b_....;;,.
32+
|+|,' | | \., ' ,' `:. _ ,/__` _=: _,'``-
33+
/ +,' | /\_........:.' '"----:::::'Y .'.| |||
34+
|' ' .'/- \ /'|| || | |||
35+
||| /| \L /'|| ||/ | |||
36+
`.| ,'/ .| / ,'||/o;/ |||
37+
`..._,, | |/| ' |||
38+
``-' | |, |||
39+
| ,. | |||
40+
,=--------.... | "" | |||
41+
,/,'. i=..+._ ,.. '..;---:::''- | |
42+
'/| __....b `-''`---....../.,Y'''''j:.,.._ | `._
43+
.' _.Y.-' `.. ii:,'--------' | :-+. .| | b\
44+
| .=_,.---'''''--...:..--:' / _..-----..:= | | '|\
45+
| '-''`'--- ---'_,,,--'' `,.. | | \.
46+
\ . ,' _,--'' :dg: _,/ ||| | \
47+
`::b\` _,-i,-' ,..---' ,|:| | _|
48+
`'--.:-._ ____,,,;.,'' `--._ '''''''' |'|' .' '
49+
``'--....Y''-' `''--..._..____._____...,' | 'o-'
50+
`''''`'''i==_+=_=i__
51+
||'''- ' `.
52+
`-.......-''
53+
*/
54+
#include<bits/stdc++.h>
55+
using namespace std;
56+
57+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
58+
#define LL long long
59+
#define mod 1000000007
60+
#define all(v) v.begin(),v.end()
61+
#define pr(v) pair<v,v>
62+
#define pb push_back
63+
#define FOR(i, j, k) for (auto i=j ; i<k ; i++)
64+
#define ROF(i, j, k) for (auto i=j ; i>=k ; i--)
65+
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
66+
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
67+
68+
const long long INF = 1e18;
69+
const long long MAX = 2e5+10;
70+
// https://atcoder.jp/contests/abc206/tasks/abc206_d
71+
vector<int>adj[MAX];
72+
vector<int>vis(MAX,0);
73+
LL dfs(int s, LL cnt, int p){
74+
if(vis[s]) return 0;
75+
vis[s] =1;
76+
for(auto i : adj[s])
77+
if(i!=p)
78+
cnt+=dfs(i,cnt,s);
79+
//cout<<s<<" "<<cnt<<" -- ";
80+
81+
return 1 + cnt;
82+
}
83+
int main(){
84+
fastio;
85+
int t=1; //cin>>t;
86+
while(t--){
87+
int n; cin>>n;
88+
int a[n];
89+
FOR(i,0,n) cin>>a[i],a[i]=1e6-a[i];
90+
FOR(i,0,n/2){
91+
if(a[i] == a[n-i-1]) continue;
92+
adj[a[i]].push_back(a[n-i-1]);
93+
adj[a[n-i-1]].push_back(a[i]);
94+
cout<<a[i]<<" "<<a[n-1-i]<<endl;
95+
// int x,y; cin>>x>>y;
96+
// adj[x].push_back(y);
97+
// adj[y].push_back(x);
98+
}
99+
LL ans = 0;
100+
FOR(i,0,n/2){
101+
if(vis[a[i]]) continue;
102+
LL cnt = dfs(a[i],0,-1)-1;
103+
// cout<<a[i]<<" "<<cnt<<endl;
104+
ans+=cnt;
105+
}
106+
cout<<ans;
107+
}
108+
}

725b.cpp

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* |\ | | ||\ \ /(_~ |~)|_~|\/||_~|\/||~)|_~|~)
2+
|~\|_|/\||~\ | ,_) |~\|__| ||__| ||_)|__|~\
3+
4+
\ //~\| | |\ |~)|_~ | ||\ ||/~\| ||_~
5+
| \_/\_/ |~\|~\|__ \_/| \||\_X\_/|__
6+
(J U S T L I K E E V E R Y O N E E L S E !)
7+
8+
__ ,..---.._
9+
+''''`--''-..`--..__
10+
.\ _,/:i--._`:-:+._`.``-._
11+
/`.._,,' \ `-.``--:.b....=.
12+
|`..__,,..`. '`.__::i--.-::_
13+
)- .....--i'\.. --+`'''-'
14+
,' .'.._,.-'|._-b\
15+
/,'<' V `oi| \ _.
16+
|/ -|,--.." ,'-. ||\.. _.,;:'_<'
17+
''/ | . ' |\||'\ /-'_/' `.
18+
|,','| , . .-.|:.`. + .,:.. |
19+
._,:'/ /-\ '^' -Y"\ |.| || /,+8d| |
20+
.|/,'| |/':: ':=:' ,'| | | \|| "+)=' |
21+
|+,';' /|_/ \ _/ \b':.\ \'| .|| ,'
22+
,,:-i''_i' | ``-.Y',. ,|`: | \;- | |_,'
23+
__ |'| |i:'._ ,' ,' ,; | |-)-' __--:b__
24+
.P| | |/,'|\ - ._ / / _,Y- ,:/' `. `'".._
25+
,'|| -','' | ._i._ `':| ,..,' ,Y;' \ `- ._
26+
|||||,.. | \ '-.._ _,' / _,b-' `. '-.
27+
||||P..i, .| '....,-' _,'''''-''' ' _,.. `\
28+
+'` <'/ |`-.....---' ._ ,._
29+
| | ,'``,:-''''/,--`.
30+
Y|.b_,,: | || ,;,Y' / |.
31+
,' /'----' .'| .. | | '" .`Y' .,-b_....;;,.
32+
|+|,' | | \., ' ,' `:. _ ,/__` _=: _,'``-
33+
/ +,' | /\_........:.' '"----:::::'Y .'.| |||
34+
|' ' .'/- \ /'|| || | |||
35+
||| /| \L /'|| ||/ | |||
36+
`.| ,'/ .| / ,'||/o;/ |||
37+
`..._,, | |/| ' |||
38+
``-' | |, |||
39+
| ,. | |||
40+
,=--------.... | "" | |||
41+
,/,'. i=..+._ ,.. '..;---:::''- | |
42+
'/| __....b `-''`---....../.,Y'''''j:.,.._ | `._
43+
.' _.Y.-' `.. ii:,'--------' | :-+. .| | b\
44+
| .=_,.---'''''--...:..--:' / _..-----..:= | | '|\
45+
| '-''`'--- ---'_,,,--'' `,.. | | \.
46+
\ . ,' _,--'' :dg: _,/ ||| | \
47+
`::b\` _,-i,-' ,..---' ,|:| | _|
48+
`'--.:-._ ____,,,;.,'' `--._ '''''''' |'|' .' '
49+
``'--....Y''-' `''--..._..____._____...,' | 'o-'
50+
`''''`'''i==_+=_=i__
51+
||'''- ' `.
52+
`-.......-''
53+
*/
54+
#include<bits/stdc++.h>
55+
using namespace std;
56+
57+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
58+
#define LL long long
59+
#define mod 1000000007
60+
#define all(v) v.begin(),v.end()
61+
#define pr(v) pair<v,v>
62+
#define pb push_back
63+
#define FOR(i, j, k) for (auto i=j ; i<k ; i++)
64+
#define ROF(i, j, k) for (auto i=j ; i>=k ; i--)
65+
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
66+
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
67+
68+
const long long INF = 1e18;
69+
const long long MAX = 2e5+10;
70+
int main(){
71+
fastio;
72+
int t=1; cin>>t;
73+
while(t--){
74+
int n; cin>>n;
75+
int a[n],s=0;
76+
FOR(i,0,n) cin>>a[i],s+=a[i];
77+
if(s%n !=0) cout<<-1<<endl;
78+
else {
79+
int k = s/n;
80+
int ans = 0;
81+
FOR(i,0,n)
82+
if(a[i]>k) ans++;
83+
cout<<ans<<endl;
84+
}
85+
86+
}
87+
}
88+
89+
// 5
90+
// 4
91+
// 4 5 2 5
92+
// 2
93+
// 0 4
94+
// 5
95+
// 10 8 5 1 4
96+
// 1
97+
// 10000
98+
// 7
99+
// 1 1 1 1 1 1 1

725c.cpp

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/* |\ | | ||\ \ /(_~ |~)|_~|\/||_~|\/||~)|_~|~)
2+
|~\|_|/\||~\ | ,_) |~\|__| ||__| ||_)|__|~\
3+
4+
\ //~\| | |\ |~)|_~ | ||\ ||/~\| ||_~
5+
| \_/\_/ |~\|~\|__ \_/| \||\_X\_/|__
6+
(J U S T L I K E E V E R Y O N E E L S E !)
7+
8+
__ ,..---.._
9+
+''''`--''-..`--..__
10+
.\ _,/:i--._`:-:+._`.``-._
11+
/`.._,,' \ `-.``--:.b....=.
12+
|`..__,,..`. '`.__::i--.-::_
13+
)- .....--i'\.. --+`'''-'
14+
,' .'.._,.-'|._-b\
15+
/,'<' V `oi| \ _.
16+
|/ -|,--.." ,'-. ||\.. _.,;:'_<'
17+
''/ | . ' |\||'\ /-'_/' `.
18+
|,','| , . .-.|:.`. + .,:.. |
19+
._,:'/ /-\ '^' -Y"\ |.| || /,+8d| |
20+
.|/,'| |/':: ':=:' ,'| | | \|| "+)=' |
21+
|+,';' /|_/ \ _/ \b':.\ \'| .|| ,'
22+
,,:-i''_i' | ``-.Y',. ,|`: | \;- | |_,'
23+
__ |'| |i:'._ ,' ,' ,; | |-)-' __--:b__
24+
.P| | |/,'|\ - ._ / / _,Y- ,:/' `. `'".._
25+
,'|| -','' | ._i._ `':| ,..,' ,Y;' \ `- ._
26+
|||||,.. | \ '-.._ _,' / _,b-' `. '-.
27+
||||P..i, .| '....,-' _,'''''-''' ' _,.. `\
28+
+'` <'/ |`-.....---' ._ ,._
29+
| | ,'``,:-''''/,--`.
30+
Y|.b_,,: | || ,;,Y' / |.
31+
,' /'----' .'| .. | | '" .`Y' .,-b_....;;,.
32+
|+|,' | | \., ' ,' `:. _ ,/__` _=: _,'``-
33+
/ +,' | /\_........:.' '"----:::::'Y .'.| |||
34+
|' ' .'/- \ /'|| || | |||
35+
||| /| \L /'|| ||/ | |||
36+
`.| ,'/ .| / ,'||/o;/ |||
37+
`..._,, | |/| ' |||
38+
``-' | |, |||
39+
| ,. | |||
40+
,=--------.... | "" | |||
41+
,/,'. i=..+._ ,.. '..;---:::''- | |
42+
'/| __....b `-''`---....../.,Y'''''j:.,.._ | `._
43+
.' _.Y.-' `.. ii:,'--------' | :-+. .| | b\
44+
| .=_,.---'''''--...:..--:' / _..-----..:= | | '|\
45+
| '-''`'--- ---'_,,,--'' `,.. | | \.
46+
\ . ,' _,--'' :dg: _,/ ||| | \
47+
`::b\` _,-i,-' ,..---' ,|:| | _|
48+
`'--.:-._ ____,,,;.,'' `--._ '''''''' |'|' .' '
49+
``'--....Y''-' `''--..._..____._____...,' | 'o-'
50+
`''''`'''i==_+=_=i__
51+
||'''- ' `.
52+
`-.......-''
53+
*/
54+
#include<bits/stdc++.h>
55+
using namespace std;
56+
57+
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
58+
#define LL long long
59+
#define mod 1000000007
60+
#define all(v) v.begin(),v.end()
61+
#define pr(v) pair<v,v>
62+
#define pb push_back
63+
#define FOR(i, j, k) for (auto i=j ; i<k ; i++)
64+
#define ROF(i, j, k) for (auto i=j ; i>=k ; i--)
65+
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
66+
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
67+
68+
const long long INF = 1e18;
69+
const long long MAX = 2e5+10;
70+
int lsearch(int v, int a[], int l, int r){
71+
int ans = INT_MAX;
72+
while(l<=r){
73+
int m = (l+r)/2;
74+
if(a[m]>=v){
75+
r = m-1;
76+
ans = m;
77+
}else l=m+1;
78+
}
79+
return ans;
80+
}
81+
82+
int rsearch(int v, int a[], int l, int r){
83+
int ans = INT_MAX;
84+
while(l<=r){
85+
int m= (l+r)/2;
86+
if(a[m]<=v){
87+
l=m+1;
88+
ans = m;
89+
}else r = m-1;
90+
}
91+
return ans;
92+
}
93+
94+
int main(){
95+
fastio;
96+
int t=1; cin>>t;
97+
while(t--){
98+
LL n,l,r; cin>>n>>l>>r;
99+
int a[n]; FOR(i,0,n) cin>>a[i];
100+
sort(a,a+n);
101+
LL ans = 0;
102+
FOR(i,0,n){
103+
int L = l-a[i],R=r-a[i];
104+
int i1 = max(i+1,lsearch(L,a,i+1,n-1));
105+
int i2 = max(i+1,rsearch(R,a,i+1,n-1));
106+
// cout<<i1<<" "<<i2<<"; ";
107+
if((i1 !=INT_MAX && i2 !=INT_MAX) && (i1!=n && i2!=n ) && i1<=i2)
108+
ans += i2-i1 +1 ;
109+
}
110+
cout<<ans<<endl;
111+
}
112+
}

0 commit comments

Comments
 (0)