結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー antaanta
提出日時 2015-09-04 15:12:15
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 4,884 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 84,312 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-18 23:42:48
合計ジャッジ時間 4,855 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 RE -
testcase_16 WA -
testcase_17 WA -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 WA -
testcase_22 RE -
testcase_23 WA -
testcase_24 WA -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:173:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  173 |             scanf("%d", &A);
      |             ~~~~~^~~~~~~~~~
main.cpp:177:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  177 |         scanf("%lld", &K);
      |         ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>

#ifdef MY_LOCAL_RUN
#include <immintrin.h>
#endif

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

#ifdef MY_LOCAL_RUN
__declspec(noinline) long long sum_trunc_mul(const double *A, int N, double s_inv) {
    __m256d inv = _mm256_set1_pd(s_inv);
    int i = 0;
    __m256d sum = _mm256_setzero_pd();
    for(; i + 3 < N; i += 4) {
        __m256d a_d = _mm256_load_pd(A + i);
        __m256d prod = _mm256_mul_pd(a_d, inv);
        __m256d truncated = _mm256_round_pd(prod, (_MM_FROUND_TO_ZERO |_MM_FROUND_NO_EXC));
        sum = _mm256_add_pd(sum, truncated);
    }
    double sum4[4];
    _mm256_storeu_pd(sum4, sum);
    long long res = 0;
    rep(k, 4) res += (ll)sum4[k];
    for(; i < N; ++ i)
        res += (ll)(A[i] * s_inv);
    return res;
}
#else
__attribute__((noinline)) long long sum_trunc_mul(const double *A, int N, double s_inv);
__asm(
"_Z13sum_trunc_mulPKdid:\n"
".L_FB3893:\n"
"	pushq	%rbp\n"
"	\n"
"	movq	%rsp, %rbp\n"
"	\n"
"	subq	$80, %rsp\n"
"	\n"
"	\n"
"	movq	%rcx, 16(%rbp)\n"
"	movl	%edx, 24(%rbp)\n"
"	vmovsd	%xmm2, 32(%rbp)\n"
"	subq	$352, %rsp\n"
"	movq	%rsp, %rax\n"
"	addq	$31, %rax\n"
"	shrq	$5, %rax\n"
"	salq	$5, %rax\n"
"	movq	32(%rbp), %rdx\n"
"	movq	%rdx, -32(%rbp)\n"
"	vbroadcastsd	-32(%rbp), %ymm0\n"
"	vmovapd	%ymm0, 256(%rax)\n"
"	movl	$0, -4(%rbp)\n"
"	vxorpd	%xmm0, %xmm0, %xmm0\n"
"	vmovapd	%ymm0, 288(%rax)\n"
"	jmp	.L_8\n"
".L_12:\n"
"	movl	-4(%rbp), %edx\n"
"	movslq	%edx, %rdx\n"
"	leaq	0(,%rdx,8), %rcx\n"
"	movq	16(%rbp), %rdx\n"
"	addq	%rcx, %rdx\n"
"	movq	%rdx, -40(%rbp)\n"
"	movq	-40(%rbp), %rdx\n"
"	vmovapd	(%rdx), %ymm0\n"
"	vmovapd	%ymm0, 224(%rax)\n"
"	vmovapd	224(%rax), %ymm0\n"
"	vmovapd	%ymm0, 128(%rax)\n"
"	vmovapd	256(%rax), %ymm0\n"
"	vmovapd	%ymm0, 96(%rax)\n"
"	vmovapd	128(%rax), %ymm0\n"
"	vmulpd	96(%rax), %ymm0, %ymm0\n"
"	vmovapd	%ymm0, 192(%rax)\n"
"	vroundpd	$11, 192(%rax), %ymm0\n"
"	vmovapd	%ymm0, 160(%rax)\n"
"	vmovapd	288(%rax), %ymm0\n"
"	vmovapd	%ymm0, 64(%rax)\n"
"	vmovapd	160(%rax), %ymm0\n"
"	vmovapd	%ymm0, 32(%rax)\n"
"	vmovapd	64(%rax), %ymm0\n"
"	vaddpd	32(%rax), %ymm0, %ymm0\n"
"	vmovapd	%ymm0, 288(%rax)\n"
"	addl	$4, -4(%rbp)\n"
".L_8:\n"
"	movl	-4(%rbp), %edx\n"
"	addl	$3, %edx\n"
"	cmpl	24(%rbp), %edx\n"
"	jl	.L_12\n"
"	leaq	-80(%rbp), %rdx\n"
"	movq	%rdx, -48(%rbp)\n"
"	vmovapd	288(%rax), %ymm0\n"
"	vmovapd	%ymm0, (%rax)\n"
"	movq	-48(%rbp), %rdx\n"
"	vmovapd	(%rax), %ymm0\n"
"	vmovupd	%ymm0, (%rdx)\n"
"	movq	$0, -16(%rbp)\n"
"	movl	$0, -20(%rbp)\n"
"	jmp	.L_13\n"
".L_14:\n"
"	movl	-20(%rbp), %eax\n"
"	cltq\n"
"	movq	-80(%rbp,%rax,8), %rax\n"
"	vmovq	%rax, %xmm1\n"
"	vcvttsd2siq	%xmm1, %rax\n"
"	addq	%rax, -16(%rbp)\n"
"	addl	$1, -20(%rbp)\n"
".L_13:\n"
"	cmpl	$3, -20(%rbp)\n"
"	jle	.L_14\n"
"	jmp	.L_15\n"
".L_16:\n"
"	movl	-4(%rbp), %eax\n"
"	cltq\n"
"	leaq	0(,%rax,8), %rdx\n"
"	movq	16(%rbp), %rax\n"
"	addq	%rdx, %rax\n"
"	movq	(%rax), %rax\n"
"	vmovq	%rax, %xmm3\n"
"	vmulsd	32(%rbp), %xmm3, %xmm0\n"
"	vcvttsd2siq	%xmm0, %rax\n"
"	addq	%rax, -16(%rbp)\n"
"	addl	$1, -4(%rbp)\n"
".L_15:\n"
"	movl	-4(%rbp), %eax\n"
"	cmpl	24(%rbp), %eax\n"
"	jl	.L_16\n"
"	movq	-16(%rbp), %rax\n"
"	movq	%rbp, %rsp\n"
"	popq	%rbp\n"
"	ret\n"
"\n");
#endif

int main() {
    int N;
    while(~scanf("%d", &N)) {
        vector<double> A_d(N);
        rep(i, N) {
            int A;
            scanf("%d", &A);
            A_d[i] = A;
        }
        long long K;
        scanf("%lld", &K);
        const double EPS = 1e-9;
        double l = 0, u = 1e9;
        while(l + EPS < u && l * (1 + EPS) < u) {
            double mid = (l + u) / 2;
            double inv = 1. / mid;
            long long sum = sum_trunc_mul(&A_d[0], N, inv);
            if(sum >= K) l = mid; else u = mid;
        }
        printf("%.10f\n", (l + u) / 2);
    }
    return 0;
}
0