# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244031 | patrikpavic2 | Cutting a rectangle (LMIO18_staciakampis) | C++17 | 24 ms | 24320 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef long long ll;
typedef pair < ll, ll > pll;
typedef pair < pll, bool > st;
const int N = 1e5 + 500;
const int M = 5e5 + 500;
vector < int > ima[M];
set < ll > svi;
queue < st > Q;
int A[N], B[N], n;
ll P = 0;
int main(){
scanf("%d", &n);
for(int i = 0;i < n;i++){
scanf("%d%d", A + i, B + i);
if(i){
ima[A[i]].PB(B[i]);
ima[B[i]].PB(A[i]);
}
P += (ll)A[i] * B[i];
}
Q.push({{A[0], B[0]}, 0});
Q.push({{A[0], B[0]}, 1});
for(int i = 0;i < M;i++)
sort(ima[i].begin(), ima[i].end());
for(;!Q.empty();Q.pop()){
st cur = Q.front();
if((ll)cur.X.X * cur.X.Y == P){
svi.insert(min(cur.X.X, cur.X.Y));
continue;
}
//printf("%d %d %d\n", cur.X.X, cur.X.Y);
if(!cur.Y){
if(cur.X.X < M){
ll dos = 0;
for(int sad : ima[cur.X.X]){
dos += sad;
Q.push({{cur.X.X, cur.X.Y + dos}, 1});
}
}
}
if(cur.Y){
if(cur.X.Y < M){
ll dos = 0;
for(int sad : ima[cur.X.Y]){
dos += sad;
Q.push({{cur.X.X + dos, cur.X.Y}, 0});
}
}
}
}
printf("%d\n", (int)svi.size());
for(ll mog : svi)
printf("%lld\n", mog);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |