Skip to content

Instantly share code, notes, and snippets.

@iray-tno
Created January 17, 2016 18:30
Show Gist options
  • Save iray-tno/e7e48f930642b8e9af52 to your computer and use it in GitHub Desktop.
Save iray-tno/e7e48f930642b8e9af52 to your computer and use it in GitHub Desktop.
#include <queue>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <iterator>
#include <cmath>
#include <tuple>
#include <stack>
#include <iomanip>
#include <string>
#include <vector>
#include <limits>
using namespace std;
int solve(){
int n;
cin >> n;
vector<int> d(n);
for(int i = 0; i < n; ++i){ cin >> d[i]; }
int ret = 0,num = 0,last = -1;
for(int i = 0; i < n; ++i){
int diff = d[i]-last;
if(num == 0){
}else if(diff<=0){
ret += 4-num;
num = 0;
}else if(10<diff){
int dret = diff/10;
if(diff%10==0) dret-=1;
dret = min(dret,4-num);
num += dret;
ret+=dret;
}else{
}
last = d[i];
++num;
num%=4;
}
ret += (4-num)%4;
return ret;
}
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
//cout << fixed << setprecision(10);
int t;
cin >> t;
for(int i = 0; i < t; ++i){
cout << "Case #" << i+1 << ": " << solve() << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment