| Bytes | Lang | Time | Link |
|---|---|---|---|
| 093 | C++ | 250222T102957Z | l4m2 |
C++, 93ms
Compile args g++ -O2, input from stdin as float128 binary, output as float128
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
typedef long double ld;
typedef unsigned uint;
void setId(ld& x, uint y) { 3[(int*)&x] = y; }
uint getId(ld& x) { return 3[(int*)&x]; }
typedef struct pz{
unsigned int a[4];
bool operator< (const pz& o) const {
return *(unsigned long*)&a[1] >
*(unsigned long*)&o.a[1]; }
} *pp;
void mult(uint N, ld* in, ld* out) {
uint M = pow(N,.7); fprintf(stderr, "IN %ld\n", clock());
static ld tmp[9999999];
for (uint i=0; i<N; ++i) {
tmp[i] = in[i];
setId(tmp[i], i);
}
for (uint i=0; i<N+N-1; ++i) {
out[i] = 0;
}
std::nth_element(pp(tmp), pp(tmp+M), pp(tmp+N));
std::sort(pp(tmp), pp(tmp+M)); fprintf(stderr, "PRE %ld %d\n", clock(), M);
for (uint i=0; i<M; ++i)
for (uint j=0; j<M; ++j) {//fprintf(stderr, "[%d %d]", M, getId(tmp[0]));
out[getId(tmp[i])+getId(tmp[j])] += tmp[i] * tmp[j];
}
ld thro = tmp[M] * tmp[M] * 1e-4;fprintf(stderr, "IRO %ld\n", clock());
int kk = 0;
for (uint i=0; i<N+N-1; ++i) if (out[i]<thro){ ++kk;
ld ret = 0;
if (i < N) {
for (uint j=0; j<=i; ++j)
ret += in[j] * in[i-j];
} else { // i-j=N-1
for (uint j=i-N+1; j<N; ++j)
ret += in[j] * in[i-j];
}
out[i] = ret;
}fprintf(stderr, "IIRO %ld %d\n", clock(), kk);
}
int main() {
const int N = 100000;
static ld Input[N];
static ld Output[N*2];
//for (uint i=0; i<N; ++i) scanf("%Le", Input+i);
fread(Input, sizeof Input, 1, stdin);
mult(N, Input, Output);
fread(Output, sizeof Output, 1, stdout);
//for (uint i=0; i<N+N-1; ++i) printf("%Le\n", Output[i]);
/*
mult(10, Input, Output);
for (int i=0; i<20; ++i) printf("%Le\n", Output[i]);*/
}
Ignore too small products