QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#60190#2173. What's Our Vector, Victor?MIT01#WA 164ms5788kbC++142.9kb2022-11-03 11:32:412022-11-03 11:32:43

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-03 11:32:43]
  • Judged
  • Verdict: WA
  • Time: 164ms
  • Memory: 5788kb
  • [2022-11-03 11:32:41]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

const double eps = 1e-9, inf = 1e9;

class Vec : public vector<double> {
  public:
    Vec() : vector<double>() {}
    Vec(size_t n) : vector<double>(n) {}
    Vec& operator-=(const Vec& oth) {
      for (size_t i = 0; i < size(); i++) {
        (*this)[i] -= oth[i];
      }
      return *this;
    }
    Vec operator*(const double k) {
      Vec result(size());
      for (size_t i = 0; i < size(); i++) {
        result[i] = (*this)[i] * k;
      }
      return result;
    }
};

double dot(const Vec& a, const Vec& b) {
  assert(a.size() == b.size());
  double r = 0;
  for (int i = 0; i < a.size(); i++)
    r += a[i]*b[i];
  return r;
}

int d, n;
double transl[505], radius;
int pivot[505];
bool ispivot[505];

int main() {
  scanf("%d%d", &d, &n);
  --n;
  for (int i = 0; i < d; i++)
    scanf("%lf", transl+i);
  scanf("%lf", &radius);
  //if (n == 0) {
    //printf("%lf", transl[0] + radius);
    //for (int i = 1; i < d; i++)
      //printf(" %lf", transl[i]);
    //return 0;
  //}

  vector<Vec> vs;
  for (int i = 0; i < n; i++) {
    Vec v(d+1);
    double sumsq = 0;
    for (int j = 0; j < d; j++) {
      double x; scanf("%lf", &x);
      x -= transl[j];
      v[j] = -2*x;
      sumsq += x*x;
    }
    double r; scanf("%lf", &r);
    v[d] = r*r - sumsq - radius*radius;
    vs.push_back(v);
  }

  for (int i = 0; i < n; i++) {
    // Find a pivot row
    int r = -1;
    for (int j = i; j < n; j++)
      if (fabs(vs[j][i]) > eps) {
        r = j;
        break;
      }
    if (r == -1)
      continue;  // None found
    if (r != i)
      swap(vs[r], vs[i]);
    vs[i] = vs[i] * (1/vs[i][i]);
    for (int j = 0; j < n; j++)
      if (j != i)
        vs[j] -= vs[i] * vs[j][i];
  }

  // Get orthonormal basis and translation for affine space
  Vec translation(d);
  for (int i = 0; i < n; i++) {
    while (pivot[i] < d && fabs(vs[i][pivot[i]]) < eps)
      pivot[i]++;
    if (pivot[i] == d)
      assert(fabs(vs[i][d]) < eps);  // Solution exists
    // Get information from row
    translation[pivot[i]] = vs[i][d];
    ispivot[pivot[i]] = true;
  }
  vector<Vec> basis;
  for (int i = 0; i < d; i++)
    if (!ispivot[i]) {
      Vec bvec(d);
      bvec[i] = -1;
      for (int j = 0; j < n; j++)
        if (pivot[j] < d)
          bvec[pivot[j]] = vs[j][i];
      basis.push_back(bvec);
    }

  // Gram schmidt
  for (int i = 0; i < basis.size(); i++) {
    for (int j = 0; j < i; j++)
      basis[i] -= basis[j] * (dot(basis[i], basis[j])/dot(basis[j], basis[j]));
    basis[i] = basis[i] * (1/sqrt(dot(basis[i], basis[i])));
  }

  // Now get projection
  for (int i = 0; i < basis.size(); i++)
    translation -= basis[i] * (dot(translation, basis[i])/dot(basis[i], basis[i]));
  if (basis.size() > 0) {
    double alpha = sqrt(radius*radius-dot(translation, translation));
    translation -= basis[0]*(-alpha);
  }

  for (int i = 0; i < d; i++)
    printf("%.9lf ", translation[i]+transl[i]);
  printf("\n");
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 154ms
memory: 5588kb

input:

500 500
60.00268893933372283 70.35885554610950976 -8.98574176457012186 46.16014112676185732 66.31422279348288384 29.03050764912902082 -35.06996828144599476 -59.10319321730690234 67.85808505028276727 20.30232033048615392 62.38784996896146140 59.92659390534240060 -36.26787439344059294 30.8251981981496...

output:

20.276643760 6.611226460 20.496149882 54.202626008 -88.967689811 92.953436921 73.119617372 12.383683359 -48.714356750 39.063450732 49.509236013 7.048771877 0.372590398 -36.280460666 -95.848995342 -68.078942857 -6.487227042 44.475893967 -28.457727875 18.831859725 30.733091923 12.408579270 3.074566477...

result:

ok accepted

Test #2:

score: 0
Accepted
time: 163ms
memory: 5712kb

input:

500 500
-20.46791708061053328 -78.90373004342441732 -47.09421721341704625 49.96697218958462372 48.99528416466444014 -46.87780686216100889 73.68284736943891744 -53.69249802982882613 -92.37158007019175443 -97.95346943385396798 -47.79109018973426259 82.31965483504592385 -72.09718577745493917 -32.376534...

output:

-2.236556046 4.309288144 -53.620359650 -31.518524438 -4.583770935 -40.693423173 -97.434823865 -70.730627392 33.850506894 40.756936240 -79.921132147 28.289981233 73.941637532 98.393392946 63.085136676 14.080487061 88.689457076 -79.011976831 -94.977138179 -18.316925156 -5.999319078 -63.047115003 -82.1...

result:

ok accepted

Test #3:

score: 0
Accepted
time: 164ms
memory: 5568kb

input:

500 500
91.75754360584323877 -74.07465057030329092 -30.06919963013949371 -22.45376960826932589 -94.33818252302211249 95.43185666705545600 -35.93139380204742395 -46.28091101025437837 20.25588702053946122 -31.98355965847254367 96.27926708531694544 17.21195108047088240 -16.00480323252260462 -14.1553994...

output:

26.238904074 -85.410279089 32.912364095 55.431160111 95.609594022 1.716248692 47.212586587 -9.661435021 97.095811637 88.482029679 53.147939972 47.970586398 -45.775642189 -37.662804845 20.553181984 -80.210083288 -81.609205988 81.831003606 63.585904435 -30.342209228 -2.614514432 69.501414148 -42.30652...

result:

ok accepted

Test #4:

score: 0
Accepted
time: 148ms
memory: 5740kb

input:

500 500
53.59239375857157484 1.29576452891167548 -55.60357761919549802 2.89491049833583247 -72.25117082444128869 -44.92736039007480997 6.81675337705620166 -46.20517542139523925 20.56179110027964896 99.93596620202598046 -30.87710828002636276 60.42621397022924157 79.91458345844398536 94.56182305252031...

output:

28.360968539 4.360562898 40.806026952 -78.278588329 78.173596836 82.169862300 92.419991685 -33.265083503 -33.305505734 -88.458669466 62.935332244 22.853065549 -91.862196529 75.296896819 27.531692518 -41.665495373 18.165541428 80.455138350 25.768106234 -12.778134068 67.545606796 -4.467014487 22.35477...

result:

ok accepted

Test #5:

score: 0
Accepted
time: 145ms
memory: 5788kb

input:

500 500
-63.61543927507285190 43.87221058298641196 8.16924114047013461 -34.92232278546450175 91.80142804719758942 -76.82013016900501157 25.06001121373941487 48.24958448628115093 65.82846176112221315 33.19899446519090702 84.05389321600614494 -78.49637158041961982 87.99406312213668002 -60.859516869891...

output:

-0.523739500 -10.730222101 -99.845937054 87.141392101 4.278321544 -50.794935581 -67.382170851 41.535111898 67.658675380 -95.297244362 62.391350653 -56.535165285 -93.735721469 -0.078493480 63.454800076 95.592490061 93.897499108 90.056511319 -1.684211621 10.650478821 79.469134090 -87.358189710 -36.483...

result:

ok accepted

Test #6:

score: -100
Wrong Answer
time: 4ms
memory: 3576kb

input:

24 114
19.60728784212125220 62.05571106800468328 -77.66722345143722350 83.32150488873739391 85.61849285200199233 -61.26186974500755866 54.01645372221616981 -19.69713224000579999 -10.16958551834513003 -18.69109461054532062 9.59051520125903778 91.21514401069063638 89.60632230190051928 -51.201061482129...

output:

19.607283523 62.055698001 -77.667156394 83.321487613 85.618492923 -60.261870128 -328.884808169 -19.697132240 -10.169585518 -18.691094611 9.590515201 91.215144011 89.606322302 -51.201061482 -15.807890220 45.211511405 -90.118464409 -25.931499244 58.202127999 62.567929378 58.779842092 90.086299324 40.1...

result:

wrong answer distance to vector 2 should be 451.98414486829949510 but is 571.29781065225074599, error 0.26397754686443087