QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#87777 | #2299. Heating Up | Bitroll | WA | 63ms | 20984kb | C++17 | 2.3kb | 2023-03-14 09:53:54 | 2023-03-14 09:53:57 |
Judging History
answer
#include<bits/stdc++.h>
#include <list>
#include <iterator>
using namespace std;
#include <iostream>
// debug util
#ifdef DEBUG
#define deb(x) cerr << #x << " = " << x << endl
#else
#define deb(x)
#endif
// useful
#define ll long long
#define umap unordered_map
bool multi = false;
void solve(){
int n, cn, mind = -1, minn; cin >> n;
list<int> cl;
int ds[n];
for(int i=0; i<n; i++){
cin >> cn;
cl.push_back(cn);
}
// 1. fill the distances arr
list<int>::iterator bit, ait, startPnt, it = cl.begin();
int db, da, index = 0;
while(it != cl.end()){
// Find the distances to the next and before elemnet
bit = ait = it;
it == --cl.end() ? ait = cl.begin() : ++ait;
it == cl.begin() ? bit = --cl.end() : --bit;
db = abs(*it - *bit);
da = abs(*it - *ait);
// Take the min one
ds[index] = min(db, da);
// If the globals were not initialized yet
if(mind == -1){
mind = ds[index];
minn = *it;
startPnt = it;
}
// If an equal distance was foumd
else if(ds[index] == mind){
if(minn > *it){
startPnt = it;
minn = *it;
}
}
// If a new min distance was found
else if((ds[index] + *it) <= (mind + minn)){
// cout << "Replacing: " << minn << " with: " << (*it) << endl;
mind = ds[index];
minn = *it;
startPnt = it;
}
// Iterate
index++;
it++;
}
// deb(mind);
// deb(minn);
// 2. Eat
int clvl = minn * 2;
int minlvl = minn;
int needs = 0;
it = startPnt; // Initialize the current iterator
while(cl.size() != 1){
// Find the lowest distance to the ngbrs
bit = it;
ait = it;
it == --cl.end() ? ait = cl.begin() : ++ait;
it == cl.begin() ? bit = --cl.end() : --bit;
// deb(*bit);
// deb(*it);
// deb(*ait);
int d1 = clvl - *bit;
int d2 = clvl - *ait;
// deb(clvl);
// deb(d1);
// deb(d2);
if(d1 > d2){
// Go to the left
needs = clvl >= *bit ? 0 : abs(d1);
clvl += *bit;
cl.erase(bit);
}else{
// Go to the right
needs = clvl >= *ait ? 0 : abs(d2);
clvl += *ait;
cl.erase(ait);
}
// deb(needs);
minlvl += needs;
clvl += needs;
}
cout << minlvl << endl;
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
if(multi)cin>>t;
while(t--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3352kb
input:
4 10 20 15 1
output:
9
result:
ok single line: '9'
Test #2:
score: -100
Wrong Answer
time: 63ms
memory: 20984kb
input:
500000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
8887080
result:
wrong answer 1st lines differ - expected: '1', found: '8887080'