From db091866d5834837a02a4a392705e81ed283c249 Mon Sep 17 00:00:00 2001 From: Darren Ha Date: Mon, 11 May 2015 13:36:47 +0900 Subject: [PATCH] ramces ... ; HosukRastaurnat done; --- .../xcshareddata/codejam.xccheckout | 4 +- cpp/codejam/sotong/HosukRestaurant.cpp | 167 ++++++++++++++++++ cpp/codejam/sotong/HosukRestaurant.txt | 18 ++ cpp/codejam/sotong/ramcesGarden.cpp | 132 ++++++++------ cpp/codejam/sotong/ramcesGarden.txt | 32 ++-- 5 files changed, 280 insertions(+), 73 deletions(-) create mode 100644 cpp/codejam/sotong/HosukRestaurant.cpp create mode 100644 cpp/codejam/sotong/HosukRestaurant.txt diff --git a/cpp/codejam.xcodeproj/project.xcworkspace/xcshareddata/codejam.xccheckout b/cpp/codejam.xcodeproj/project.xcworkspace/xcshareddata/codejam.xccheckout index 32d52af..3e80418 100644 --- a/cpp/codejam.xcodeproj/project.xcworkspace/xcshareddata/codejam.xccheckout +++ b/cpp/codejam.xcodeproj/project.xcworkspace/xcshareddata/codejam.xccheckout @@ -7,14 +7,14 @@ IDESourceControlProjectIdentifier FCD35A5D-6DCF-4089-BEC9-F01A76C27723 IDESourceControlProjectName - project + codejam IDESourceControlProjectOriginsDictionary 2D0A34A56895B8218D331D945207F18F09C45FEF https://github.com/nberserk/codejam.git IDESourceControlProjectPath - cpp/codejam.xcodeproj/project.xcworkspace + cpp/codejam.xcodeproj IDESourceControlProjectRelativeInstallPathDictionary 2D0A34A56895B8218D331D945207F18F09C45FEF diff --git a/cpp/codejam/sotong/HosukRestaurant.cpp b/cpp/codejam/sotong/HosukRestaurant.cpp new file mode 100644 index 0000000..2a8a91a --- /dev/null +++ b/cpp/codejam/sotong/HosukRestaurant.cpp @@ -0,0 +1,167 @@ +#include +#ifdef _MSC_VER +#include +#define F_OK 0 +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "../myutil.h" + + +using namespace std; +#define H_MAX 987654321 +#define H_MIN -987654321 +#define H_EPSILON 0.000001 +#define MOD 100000 +typedef long long ll; + + +void check(bool ret){ + if (ret==false) { + printf("failed\n"); + } +} +void check(int expected, int actual){ + if (expected!=actual) { + printf("failed expected=%d, actual=%d\n", expected, actual); + } +} +void check(char expected, char actual){ + if (expected!=actual) { + printf("failed expected=%c, actual=%c\n", expected, actual); + } +} + +//#define MAX_N 1000001 +#define MAX_N 500000 +bool gDebug; +int gN; +struct Price{ + int a,b; +}; + +Price price[MAX_N]; +int gMinAFromBack[MAX_N]; +int gMinAMinusB[MAX_N]; +long long gSumB[MAX_N]; + +void swap(int i,int j){ + Price t = price[i]; + price[i]= price[j]; + price[j]=t; +} + +int partition(int s, int e){ + int p = price[e].b; + + int j=s-1; + for(int i=s;i= 0; i--){ + if (price[i].a < m){ + m=price[i].a; + } + gMinAFromBack[i]=m; + } + + ll r=gMinAFromBack[0]; // K=1 + r+=gSumB[gN-1]+gMinAMinusB[gN-1] ;//K=N + ll a,b,d; + for (int i = 1; i < gN-1; i++){ + a = gSumB[i]+gMinAMinusB[i]; + b = gSumB[i-1] + gMinAFromBack[i+1]; + d = a>b ? b:a; + r += d; + r %=MOD; + } + printf("%d\n", r); +} + +void test(){ + +} + +int main(){ + string fn = __FILE__; + size_t pos = fn.find(".cpp"); + fn = fn.substr(0,pos) + ".txt"; + if (access(fn.c_str(), F_OK)!=-1) { + gDebug = true; + } + + FILE *fp; + if (gDebug) { + fp = freopen(fn.c_str(), "r", stdin); + } + + //h_generateRandomMap(100); + //test(); + //precalc(); + + // handling input + int count, p,j,k, i,n; + scanf("%d", &count); + for (p=0; p