/ Randle /

记录详情

Memory Exceeded

/in/foo.cc: In function 'int zoulouti1(int)':
/in/foo.cc:8:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(n <= louti.size()) // 已经计算过的楼梯级,直接返回vector里面的值即可
        ~~^~~~~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Wrong Answer 1ms 196.0 KiB
#2 Wrong Answer 1ms 204.0 KiB
#3 Wrong Answer 1ms 208.0 KiB
#4 Memory Exceeded ≥295ms ≥256.0 MiB
#5 Memory Exceeded ≥302ms ≥256.0 MiB
#6 Memory Exceeded ≥266ms ≥256.0 MiB
#7 Memory Exceeded ≥268ms ≥256.0 MiB
#8 Memory Exceeded ≥260ms ≥256.0 MiB
#9 Memory Exceeded ≥264ms ≥256.0 MiB
#10 Memory Exceeded ≥261ms ≥256.0 MiB

代码

#include <vector>
#include <iostream>
using namespace std;

static vector<int> louti;
int zoulouti1(int n)
{
    if(n <= louti.size()) // 已经计算过的楼梯级,直接返回vector里面的值即可
        return louti[n - 1];
    int i = louti.size();
    while(i < n) {
        // f(n) = f(n - 1) + f(n - 2) + f(n - 3)
        int zoufa = louti[i - 1] + louti[i - 2] + louti[i - 3];
        louti.push_back(zoufa);
        ++i;
    }
    return louti.back();
}
void init_louti()
{
    // 只有1、2、3级楼梯,对应的走法
    louti.push_back(1);
    louti.push_back(2);
    louti.push_back(4);
}
int main()
{
    int n = 0;
    cin >> n;
    init_louti();
    cout <<  zoulouti1(n) << endl;
}

信息

递交者
类型
递交
题目
上楼梯(数据原创)
题目数据
下载
语言
C++
递交时间
2019-10-28 11:08:23
评测时间
2019-10-28 11:08:23
评测机
分数
0
总耗时
≥1924ms
峰值内存
≥256.0 MiB