#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
const ll M=1e6;
ll n,s,t,cnt[M],curc[M],rc[M];
vii a[M],ans[M];
vii res;
bool vis[M];
vector<pii>edges;
vector<pii>eul[M],adj[M];
map<pii,ll>col;
vii euler;
ll cc[M],ccc[M];
void dfs(ll x,ll pa=-1) {
if(vis[x])
return;
vis[x]=1;
if(eul[x][0].F==x) {
ans[eul[x][0].S].pb(x),ans[eul[x][0].S].pb(x);
return;
}
if(eul[x][0].F==pa)
swap(eul[x][0],eul[x][1]);
ans[eul[x][0].S].pb(x),ans[eul[x][0].S].pb(eul[x][0].F);
dfs(eul[x][0].F,x);
}
vector<pii>ee;
void tour(ll x,ll par=-1) {
while(adj[x].size()>0) {
if(vis[adj[x].back().S]) {
adj[x].pop_back();
continue;
}
ll y=adj[x].back().F;
vis[adj[x].back().S]=1;
adj[x].pop_back();
tour(y,x);
}
// cout<<x<<' '<<par<<endl;
if(par>=0)
ee.pb({x,par});
}
void DaC(ll sz,vector<pii> e) {
//cout<<e.size()<<' ';
for(int i=0;i<2*n;i++)
adj[i].clear();
if(sz==2) {
for(int i=0;i<n;i++)
cc[i]=ans[i].size();
for(int i=0;i<n;i++)
vis[i]=0;
for(auto it:e)
adj[it.F].pb({it.S,0}),adj[it.S].pb({it.F,0});
vector<pair<ll,pii>>v;
for(int i=0;i<n;i++) {
v.pb({i,{adj[i][0].F-n,adj[i][1].F-n}});
}
for(int i=0;i<n;i++)
eul[i].clear();
for(auto it:v) {
eul[it.S.F].pb({it.S.S,it.F});
eul[it.S.S].pb({it.S.F,it.F});
}
for(int i=0;i<n;i++) {
if(!vis[i])
dfs(i);
}
for(int i=0;i<n;i++)
vis[i]=0;
return;
}
ll c=0;
for(auto it:e) {
vis[c]=0;
adj[it.F].pb({it.S,c});
adj[it.S].pb({it.F,c++});
// cout<<it.F<<' '<<it.S<<' '<<c<<endl;
}
ee.clear();
tour(0);
vector<pii>e1,e2;
for(int i=0;i<ee.size();i++) {
if(i%2==0)
e1.pb(ee[i]);
else
e2.pb(ee[i]);
}
euler.clear();
DaC(sz/2,e1),DaC(sz/2,e2);
}
int main() {
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>n>>s>>t;
t=0;
for(int i=0;i<n;i++) {
a[i].resize(s);
for(int j=0;j<s;j++) {
cin>>a[i][j];
cnt[a[i][j]]++;
}
}
for(int i=0;i<n;i++) {
for(int j=0;j<s;j++) {
if(cnt[a[i][j]]%s==0)
curc[a[i][j]]=t++;
cnt[a[i][j]]--;
rc[curc[a[i][j]]]=a[i][j];
edges.pb({curc[a[i][j]]+n,i});
}
}
DaC(s,edges);
for(int i=0;i<n;i++) {
for(auto it:ans[i])
cout<<rc[it]<<' ';
cout<<'\n';
}
return 0;
}
Compilation message
balance.cpp: In function 'void DaC(ll, std::vector<std::pair<long long int, long long int> >)':
balance.cpp:88:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int i=0;i<ee.size();i++) {
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
108 ms |
191056 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
102 ms |
190892 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
130932 KB |
Correct |
2 |
Correct |
129 ms |
129212 KB |
Correct |
3 |
Correct |
114 ms |
123832 KB |
Correct |
4 |
Correct |
91 ms |
124604 KB |
Correct |
5 |
Correct |
114 ms |
131384 KB |
Correct |
6 |
Correct |
126 ms |
130860 KB |
Correct |
7 |
Correct |
134 ms |
126832 KB |
Correct |
8 |
Correct |
101 ms |
132024 KB |
Correct |
9 |
Correct |
112 ms |
132532 KB |
Correct |
10 |
Correct |
96 ms |
131264 KB |
Correct |
11 |
Correct |
92 ms |
130996 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
130932 KB |
Correct |
2 |
Correct |
129 ms |
129212 KB |
Correct |
3 |
Correct |
114 ms |
123832 KB |
Correct |
4 |
Correct |
91 ms |
124604 KB |
Correct |
5 |
Correct |
114 ms |
131384 KB |
Correct |
6 |
Correct |
126 ms |
130860 KB |
Correct |
7 |
Correct |
134 ms |
126832 KB |
Correct |
8 |
Correct |
101 ms |
132024 KB |
Correct |
9 |
Correct |
112 ms |
132532 KB |
Correct |
10 |
Correct |
96 ms |
131264 KB |
Correct |
11 |
Correct |
92 ms |
130996 KB |
Correct |
12 |
Correct |
156 ms |
131000 KB |
Correct |
13 |
Correct |
132 ms |
129100 KB |
Correct |
14 |
Correct |
114 ms |
123832 KB |
Correct |
15 |
Correct |
105 ms |
124568 KB |
Correct |
16 |
Correct |
126 ms |
131256 KB |
Correct |
17 |
Correct |
129 ms |
130740 KB |
Correct |
18 |
Correct |
130 ms |
126912 KB |
Correct |
19 |
Correct |
112 ms |
131972 KB |
Correct |
20 |
Correct |
103 ms |
132424 KB |
Correct |
21 |
Correct |
93 ms |
131260 KB |
Correct |
22 |
Correct |
98 ms |
130996 KB |
Correct |
23 |
Runtime error |
176 ms |
253624 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
102 ms |
190892 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
94296 KB |
Correct |
2 |
Correct |
42 ms |
96856 KB |
Correct |
3 |
Correct |
42 ms |
96716 KB |
Correct |
4 |
Correct |
43 ms |
96720 KB |
Correct |
5 |
Correct |
40 ms |
95892 KB |
Correct |
6 |
Correct |
40 ms |
96152 KB |
Correct |
7 |
Correct |
40 ms |
96600 KB |
Correct |
8 |
Correct |
44 ms |
96844 KB |
Correct |
9 |
Correct |
40 ms |
96592 KB |
Correct |
10 |
Correct |
51 ms |
96660 KB |
Correct |
11 |
Correct |
44 ms |
96612 KB |
Correct |
12 |
Correct |
45 ms |
96152 KB |
Correct |
13 |
Correct |
39 ms |
96156 KB |
Correct |
14 |
Correct |
42 ms |
96176 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
94296 KB |
Correct |
2 |
Correct |
42 ms |
96856 KB |
Correct |
3 |
Correct |
42 ms |
96716 KB |
Correct |
4 |
Correct |
43 ms |
96720 KB |
Correct |
5 |
Correct |
40 ms |
95892 KB |
Correct |
6 |
Correct |
40 ms |
96152 KB |
Correct |
7 |
Correct |
40 ms |
96600 KB |
Correct |
8 |
Correct |
44 ms |
96844 KB |
Correct |
9 |
Correct |
40 ms |
96592 KB |
Correct |
10 |
Correct |
51 ms |
96660 KB |
Correct |
11 |
Correct |
44 ms |
96612 KB |
Correct |
12 |
Correct |
45 ms |
96152 KB |
Correct |
13 |
Correct |
39 ms |
96156 KB |
Correct |
14 |
Correct |
42 ms |
96176 KB |
Correct |
15 |
Correct |
37 ms |
94292 KB |
Correct |
16 |
Correct |
42 ms |
96928 KB |
Correct |
17 |
Correct |
42 ms |
96728 KB |
Correct |
18 |
Correct |
43 ms |
96852 KB |
Correct |
19 |
Correct |
42 ms |
95900 KB |
Correct |
20 |
Correct |
41 ms |
96152 KB |
Correct |
21 |
Correct |
40 ms |
96512 KB |
Correct |
22 |
Correct |
45 ms |
96848 KB |
Correct |
23 |
Correct |
45 ms |
96592 KB |
Correct |
24 |
Correct |
42 ms |
96848 KB |
Correct |
25 |
Correct |
44 ms |
96608 KB |
Correct |
26 |
Correct |
40 ms |
96156 KB |
Correct |
27 |
Correct |
37 ms |
96160 KB |
Correct |
28 |
Correct |
41 ms |
96156 KB |
Correct |
29 |
Runtime error |
110 ms |
195640 KB |
Execution killed with signal 11 |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
94296 KB |
Correct |
2 |
Correct |
42 ms |
96856 KB |
Correct |
3 |
Correct |
42 ms |
96716 KB |
Correct |
4 |
Correct |
43 ms |
96720 KB |
Correct |
5 |
Correct |
40 ms |
95892 KB |
Correct |
6 |
Correct |
40 ms |
96152 KB |
Correct |
7 |
Correct |
40 ms |
96600 KB |
Correct |
8 |
Correct |
44 ms |
96844 KB |
Correct |
9 |
Correct |
40 ms |
96592 KB |
Correct |
10 |
Correct |
51 ms |
96660 KB |
Correct |
11 |
Correct |
44 ms |
96612 KB |
Correct |
12 |
Correct |
45 ms |
96152 KB |
Correct |
13 |
Correct |
39 ms |
96156 KB |
Correct |
14 |
Correct |
42 ms |
96176 KB |
Correct |
15 |
Correct |
37 ms |
94292 KB |
Correct |
16 |
Correct |
42 ms |
96928 KB |
Correct |
17 |
Correct |
42 ms |
96728 KB |
Correct |
18 |
Correct |
43 ms |
96852 KB |
Correct |
19 |
Correct |
42 ms |
95900 KB |
Correct |
20 |
Correct |
41 ms |
96152 KB |
Correct |
21 |
Correct |
40 ms |
96512 KB |
Correct |
22 |
Correct |
45 ms |
96848 KB |
Correct |
23 |
Correct |
45 ms |
96592 KB |
Correct |
24 |
Correct |
42 ms |
96848 KB |
Correct |
25 |
Correct |
44 ms |
96608 KB |
Correct |
26 |
Correct |
40 ms |
96156 KB |
Correct |
27 |
Correct |
37 ms |
96160 KB |
Correct |
28 |
Correct |
41 ms |
96156 KB |
Correct |
29 |
Runtime error |
110 ms |
195640 KB |
Execution killed with signal 11 |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
130932 KB |
Correct |
2 |
Correct |
129 ms |
129212 KB |
Correct |
3 |
Correct |
114 ms |
123832 KB |
Correct |
4 |
Correct |
91 ms |
124604 KB |
Correct |
5 |
Correct |
114 ms |
131384 KB |
Correct |
6 |
Correct |
126 ms |
130860 KB |
Correct |
7 |
Correct |
134 ms |
126832 KB |
Correct |
8 |
Correct |
101 ms |
132024 KB |
Correct |
9 |
Correct |
112 ms |
132532 KB |
Correct |
10 |
Correct |
96 ms |
131264 KB |
Correct |
11 |
Correct |
92 ms |
130996 KB |
Correct |
12 |
Correct |
40 ms |
94296 KB |
Correct |
13 |
Correct |
42 ms |
96856 KB |
Correct |
14 |
Correct |
42 ms |
96716 KB |
Correct |
15 |
Correct |
43 ms |
96720 KB |
Correct |
16 |
Correct |
40 ms |
95892 KB |
Correct |
17 |
Correct |
40 ms |
96152 KB |
Correct |
18 |
Correct |
40 ms |
96600 KB |
Correct |
19 |
Correct |
44 ms |
96844 KB |
Correct |
20 |
Correct |
40 ms |
96592 KB |
Correct |
21 |
Correct |
51 ms |
96660 KB |
Correct |
22 |
Correct |
44 ms |
96612 KB |
Correct |
23 |
Correct |
45 ms |
96152 KB |
Correct |
24 |
Correct |
39 ms |
96156 KB |
Correct |
25 |
Correct |
42 ms |
96176 KB |
Correct |
26 |
Correct |
138 ms |
131008 KB |
Correct |
27 |
Correct |
118 ms |
129212 KB |
Correct |
28 |
Correct |
148 ms |
123800 KB |
Correct |
29 |
Correct |
94 ms |
124604 KB |
Correct |
30 |
Correct |
128 ms |
131324 KB |
Correct |
31 |
Correct |
138 ms |
130836 KB |
Correct |
32 |
Correct |
131 ms |
126908 KB |
Correct |
33 |
Correct |
107 ms |
131888 KB |
Correct |
34 |
Correct |
113 ms |
132552 KB |
Correct |
35 |
Correct |
98 ms |
131204 KB |
Correct |
36 |
Correct |
114 ms |
130948 KB |
Correct |
37 |
Correct |
45 ms |
94512 KB |
Correct |
38 |
Correct |
46 ms |
96876 KB |
Correct |
39 |
Correct |
51 ms |
96628 KB |
Correct |
40 |
Correct |
39 ms |
96700 KB |
Correct |
41 |
Correct |
47 ms |
95832 KB |
Correct |
42 |
Correct |
44 ms |
96148 KB |
Correct |
43 |
Correct |
41 ms |
96604 KB |
Correct |
44 |
Correct |
40 ms |
96856 KB |
Correct |
45 |
Correct |
45 ms |
96536 KB |
Correct |
46 |
Correct |
43 ms |
96860 KB |
Correct |
47 |
Correct |
48 ms |
96584 KB |
Correct |
48 |
Correct |
40 ms |
96164 KB |
Correct |
49 |
Correct |
43 ms |
96160 KB |
Correct |
50 |
Correct |
39 ms |
96096 KB |
Correct |
51 |
Correct |
400 ms |
217568 KB |
Correct |
52 |
Correct |
376 ms |
213180 KB |
Correct |
53 |
Correct |
117 ms |
118220 KB |
Correct |
54 |
Correct |
135 ms |
140848 KB |
Correct |
55 |
Correct |
331 ms |
202800 KB |
Correct |
56 |
Correct |
361 ms |
212248 KB |
Correct |
57 |
Correct |
394 ms |
217632 KB |
Correct |
58 |
Incorrect |
398 ms |
212908 KB |
Output for core 8 doesn't match the input tasks |
59 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
130932 KB |
Correct |
2 |
Correct |
129 ms |
129212 KB |
Correct |
3 |
Correct |
114 ms |
123832 KB |
Correct |
4 |
Correct |
91 ms |
124604 KB |
Correct |
5 |
Correct |
114 ms |
131384 KB |
Correct |
6 |
Correct |
126 ms |
130860 KB |
Correct |
7 |
Correct |
134 ms |
126832 KB |
Correct |
8 |
Correct |
101 ms |
132024 KB |
Correct |
9 |
Correct |
112 ms |
132532 KB |
Correct |
10 |
Correct |
96 ms |
131264 KB |
Correct |
11 |
Correct |
92 ms |
130996 KB |
Correct |
12 |
Correct |
156 ms |
131000 KB |
Correct |
13 |
Correct |
132 ms |
129100 KB |
Correct |
14 |
Correct |
114 ms |
123832 KB |
Correct |
15 |
Correct |
105 ms |
124568 KB |
Correct |
16 |
Correct |
126 ms |
131256 KB |
Correct |
17 |
Correct |
129 ms |
130740 KB |
Correct |
18 |
Correct |
130 ms |
126912 KB |
Correct |
19 |
Correct |
112 ms |
131972 KB |
Correct |
20 |
Correct |
103 ms |
132424 KB |
Correct |
21 |
Correct |
93 ms |
131260 KB |
Correct |
22 |
Correct |
98 ms |
130996 KB |
Correct |
23 |
Runtime error |
176 ms |
253624 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
108 ms |
191056 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |