이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int TAILLE_MAX=100*1000+5;
int nbPort,ligPrem,colPrem;
int mat[2][TAILLE_MAX];
vector<int> listeNonNul;
void echange(int colDeb,int colFin) {
swap(mat[0][colDeb],mat[0][colFin]);
swap(mat[1][colDeb],mat[1][colFin]);
}
void posit(int col) {
if (mat[0][col]<0) {
mat[0][col]*=-1;
mat[1][col]*=-1;
}
}
void modif(int colModif,int colAj,int coeff) {
mat[0][colModif]+=coeff*mat[0][colAj];
mat[1][colModif]+=coeff*mat[1][colAj];
}
void calc(int colDeb,int colFin) {
posit(colDeb);
posit(colFin);
if (mat[0][colDeb]<mat[0][colFin]) {
echange(colDeb,colFin);
}
while (mat[0][colFin]>0) {
modif(colDeb,colFin,mat[0][colDeb]/mat[0][colFin]);
echange(colDeb,colFin);
}
}
int pgcd(vector<int> v) {
int ans=v[0];
for (int i=1;i<(int)v.size();i++) {
ans=gcd(ans,v[i]);
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>nbPort;
cin>>colPrem>>ligPrem;
if (nbPort<=2) {
cout<<-1<<endl;
return 0;
}
int colNouv,ligNouv;
for (int i=0;i<nbPort-1;i++) {
cin>>colNouv>>ligNouv;
mat[0][i]=ligNouv-ligPrem;
mat[1][i]=colNouv-colPrem;
}
for (int i=1;i<nbPort-1;i++) {
calc(0,i);
}
for (int i=1;i<nbPort-1;i++) {
if (mat[1][i]!=0) {
listeNonNul.push_back(abs(mat[1][i]));
}
}
int rep=mat[0][0]*mat[1][1];
if (rep==0) {
cout<<-1<<endl;
}
else {
cout<<abs(rep)<<endl;
}
/*if (listeNonNul.empty()) {
cout<<-1<<endl;
}
else {
cout<<abs(mat[0][0]*pgcd(listeNonNul))<<endl;
}*/
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |