Last active
October 18, 2020 15:16
-
-
Save chaidhat/634a7b4c584088afecaf800edda1dd83 to your computer and use it in GitHub Desktop.
Kick Start round E 23/08/2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23-AUG-2020 | |
Chaidhat Chaimongkol | |
Partial Attempt - Place didn't count (Joined at 1 hour remaining) | |
9101/11400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// attempt 1: CHECK | TLE | |
/* | |
#include<iostream> | |
#include <sstream> | |
using namespace std; | |
int main () | |
{ | |
int T; // test cases | |
cin >> T; | |
for (int i = 0; i < T; i++) | |
{ | |
int N; // numbers to follow | |
cin >> N; | |
int num[N]; // numbers | |
for (int n = 0; n < N; n++) | |
{ | |
cin >> num[n]; | |
} | |
int output = 0; | |
int held = 0; | |
int n2 = 1; | |
for (int n = 0; n < N - 1; n++) | |
{ | |
int numRatio = num[n+1] - num[n]; | |
int ratio; | |
ratio = num[n2+1] - num[n2]; | |
cout << numRatio << "\n"; | |
if (ratio == numRatio) | |
{ | |
held++; | |
if (held > output) | |
output = held; | |
} | |
else | |
{ | |
held = 0; | |
} | |
n2++; | |
do | |
{ | |
ratio = num[n2+1] - num[n2]; | |
cont++; | |
if (cont > output) | |
output = cont; | |
n2++; | |
}while (ratio == numRatio); | |
} | |
cout << "case #" << (i + 1) << ": " << output << "\n"; | |
} | |
} | |
*/ | |
// attempt 2: WA | Test set skipped | |
#include<iostream> | |
#include <sstream> | |
using namespace std; | |
int main () | |
{ | |
int T; // test cases | |
cin >> T; | |
for (int i = 0; i < T; i++) | |
{ | |
int N; // numbers to follow | |
cin >> N; | |
int num[N]; // numbers | |
for (int n = 0; n < N; n++) | |
{ | |
cin >> num[n]; | |
} | |
int output = 0; | |
int ratio[N]; | |
int old = 0; | |
int held = 0; | |
for (int n = 0; n < N; n++) | |
{ | |
ratio[n] = num[n] - num[n-1]; | |
if (ratio[n] == ratio[n-1]) | |
{ | |
if (held == 0) | |
held = 1; | |
held++; | |
} | |
else | |
{ | |
held = 0; | |
} | |
if ((held) > output) | |
output = held; | |
cout << ratio[n] << " num[n]:" << num[n] << " num[n-1]:" << num[n-1] << " held:" << held << "\n"; | |
} | |
cout << "case #" << (i + 1) << ": " << output << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment