QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59523#3894. Generator GridHawaraWA 27ms128660kbC++142.0kb2022-10-30 07:12:132022-10-30 07:12:15

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-10-30 07:12:15]
  • Judged
  • Verdict: WA
  • Time: 27ms
  • Memory: 128660kb
  • [2022-10-30 07:12:13]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
const long long MOD = 1e9 + 7, OO = 1e18;
const double PI = acos(-1);
const int N = 1e6 + 5;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

ll n, m, pl[N], u, v, mem[N][2][2][2][2];
pair<ll, ll>plant[N];

ll dp(ll i, bool pre, bool curr, bool first, bool final)
{
    ll &ret = mem[i][pre][curr][first][final];
    if (~ret)return ret;

    if (i == n)
    {
        if (final == 1)return 0;
        ll c1 = OO, c2 = OO;
        if (pre)c1 = pl[n - 1];
        if (first)c2 = pl[n];
        ret = min(c1, c2);
    }
    else 
    {
        ll c1 = OO, c2 = OO, c3 = OO;
        if (plant[i].first)
        {
            if (i == 1)first = 1;
            c1 = plant[i].second + dp(i + 1, 1, 0, first, final);
        }
        if (pre && curr == 0)
        {
            ll prev = i - 1;
            if (prev == 0)prev = n;
            if (i == 1)first = 0;
            c2 = pl[prev] + dp(i + 1, 0, 0, first, final);
        }
        if (curr == 0 && plant[i + 1].first && !(i + 1 == n && final == 0))
        {
            if (i == 1)first = 0;
            c3 = pl[i] + dp(i + 1, 0, 1, first, final);
        }
        ret = min({c1, c2, c3});
    }

    return ret;
}   

int main()
{
    IO  
    memset(mem, -1, sizeof mem);
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> u >> v;
        plant[u] = {1, v};
    }
    for (int i = 1; i <= n; i++)cin >> pl[i];
    cout << min(dp(1, 0, 0, 0, 0), plant[n].second * plant[n].first + dp(1, plant[n].first, 0, 0, plant[n].first));
    return 0;   
}

详细

Test #1:

score: 100
Accepted
time: 27ms
memory: 128512kb

input:

3 2
1 100
2 200
150 300 150

output:

400

result:

ok single line: '400'

Test #2:

score: 0
Accepted
time: 25ms
memory: 128532kb

input:

3 2
1 100
2 200
300 300 150

output:

450

result:

ok single line: '450'

Test #3:

score: -100
Wrong Answer
time: 25ms
memory: 128660kb

input:

100 1
1 100
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...

output:

1000000000000000000

result:

wrong answer 1st lines differ - expected: '1090', found: '1000000000000000000'