求调
查看原帖
求调
1392551
ruo_aqueous楼主2024/11/21 22:32

所以到底错哪了!!??

#include <bits/stdc++.h>
using namespace std;
long long n,h,m,s[1145100],maxx=0,now,now_sum,now_2,j;
int main(){
	cin >>h >>n;
	for (long long o = 1;o <= 2;o ++){
	    if (o == 1) now=0;
		for (long long i = 0;i < n;i ++){
			if (o == 1) cin >>s[i];
			now += s[i];
			if (now >= h){
				cout <<o-1 <<" " <<i;
				return 0;
			}
			// 如果中途可以到达 
			now=max(now,(long long)0);
			maxx=max(maxx,now); 
			// 最低高度为 0 
		}
		if (o == 1) now_sum = now;
	}
	
	if (now_sum>0 and now_sum != now){
		j=((h-maxx)/now);
		if ((h-maxx)%now != 0)	j ++;
		now_2=now_sum;now_2 *= j;
		if (now_2 >= h){
			cout <<j <<" 0";
			return 0;
		}
		for (long long i = 0;i < n;i ++){
			now_2 += s[i];
			now_2=max(now_sum,(long long)0);
			if (now_2 >= h){
				cout <<j <<" " <<i;
				return 0;
			}
		}
	}
	// 如果每次都能往上 
	else cout <<"-1 -1";
	return 0;
}
// 我的
/* 官方的
#include <cstdio>
#include <algorithm>
#include <assert.h>
#define INF 1012345678012345678LL
#define BIG 1000000000000LL
using namespace std;
typedef long long ll;
ll H;
int N;
ll P[10010];
ll simulate[20010]; // 是 P_i
ll increment = 0; // increment 增量,每次增长多少
bool printed = 0;
int main(void) {
    scanf("%lld%d", &H, &N);
    assert(1<=H && H<=BIG);
    assert(1<=N && N<=10000);//防君子不防小人
    for (int i=0;i<N;i++) {
        scanf("%lld", &P[i]);
        assert(-BIG<=P[i] && P[i]<=BIG);
    }
    // **模拟 2 天**
    simulate[0] = 0;
    for (int i=0;i<2*N;i++) { // 你可能忘记它而爆 37 pts
        simulate[i+1] = max(simulate[i]+P[i%N], 0LL); // 记得取 max
        if (simulate[i+1] >= H) { // 第一次就超过了
            printf("%d %d\n", i/N, i%N);
            printed = 1;
            break;
        }
    }
    if (!printed) {
        for (int i=0;i<N;i++) {
            increment += P[i]; // 可能向下到负数
            // 如果真到了呢?
            if (increment <= -H) { // 不可能的
                printf("-1 -1\n");
                printed = true;
                break;
            }
        }
    }
    if (!printed) {
        // 每天退步一点点
        if (increment <= 0) {
            // 那就不用爬了
            printf("-1 -1\n");
            printed = true;
        } else {
            ll bestDays = INF;
            int phase = 0;
            for (int i=0;i<N;i++) {
                ll days = 1+(H-simulate[N+i+1]+increment-1)/increment;
                if (bestDays > days) {
                    bestDays = days;
                    phase = i;
                }
            }
            printf("%lld %d\n", bestDays, phase);
            printed = true;
        }
    }
    return 0;
}
*/
2024/11/21 22:32
加载中...