-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f11a805
commit a6d794e
Showing
16 changed files
with
12,955 additions
and
36 deletions.
There are no files selected for viewing
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
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
void wiggle_sort(vector<int>& s) { | ||
int n = (int)s.size(); | ||
if(n == 0) return; | ||
|
||
bool flag = true; | ||
int current = s[0]; | ||
for (int i = 0; i < n-1; i++) { | ||
if ((flag && current > s[i+1]) || (!flag && current < s[i+1])) { | ||
s[i] = s[i+1]; | ||
} else { | ||
s[i] = current; | ||
current = s[i+1]; | ||
bool subarray_sum(vector<int>& arr, int t) { | ||
int curr_sum = arr[0], start = 0, i; | ||
|
||
for (i = 1; i <= arr.size(); i++) { | ||
while (curr_sum > t && start < i-1) { | ||
curr_sum = curr_sum - arr[start]; | ||
start++; | ||
} | ||
flag = !flag; | ||
|
||
if (curr_sum == t) return true; | ||
if (i < arr.size()) curr_sum = curr_sum + arr[i]; | ||
} | ||
s[n-1] = current; | ||
return false; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const int num_test = 100; | ||
vector<vector<int>> in_0; | ||
vector<vector<int>> in_org_0; | ||
vector<int> in_1; | ||
vector<int> in_org_1; | ||
vector<bool> out; | ||
|
||
|
||
void load_test() { | ||
ifstream in("judge/tests/subarray-sum.txt"); | ||
read_matrix(in, in_0); | ||
in_org_0 = clone(in_0); | ||
read_array(in, in_1); | ||
in_org_1 = clone(in_1); | ||
read_array(in, out); | ||
in.close(); | ||
} | ||
|
||
void judge() { | ||
cout.setf(ios::boolalpha); | ||
|
||
capture_stdout(); | ||
|
||
load_test(); | ||
auto start = chrono::steady_clock::now(); | ||
for(int i = 0; i < num_test; ++i) { | ||
printf("Testing case #%d\n", i+1); | ||
auto answer = subarray_sum(in_0[i], in_1[i]); | ||
if(answer != out[i]) { | ||
release_stdout(); | ||
cout << i+1 << "/" << num_test << ";"; | ||
cout << in_org_0[i] << + ", " << in_org_1[i] << ";"; | ||
cout << answer << ";"; | ||
cout << out[i] << endl; | ||
return; | ||
} | ||
} | ||
release_stdout(); | ||
auto elapsed = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start); | ||
cout << "Accepted;"; | ||
cout << elapsed.count() << endl; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,5 @@ | ||
package judge;import java.util.*;import java.lang.*;import java.io.*;import datastruct.*; public class Solution { | ||
public void wiggle_sort(int[] s) { | ||
int n = s.length; | ||
if(n == 0) return; | ||
|
||
boolean flag = true; | ||
int current = s[0]; | ||
for (int i = 0; i < n-1; i++) { | ||
if ((flag && current > s[i+1]) || (!flag && current < s[i+1])) { | ||
s[i] = s[i+1]; | ||
} else { | ||
s[i] = current; | ||
current = s[i+1]; | ||
} | ||
flag = !flag; | ||
} | ||
s[n-1] = current; | ||
public boolean subarray_sum(int[] array, int t) { | ||
return false; | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package tests; | ||
import java.util.*; | ||
import java.lang.*; | ||
import java.io.*; | ||
import judge.*; | ||
import datastruct.*; | ||
|
||
public class subarray_sum { | ||
public static int num_test = 100; | ||
public static int[][] in_0; | ||
public static int[][] in_org_0; | ||
public static int[] in_1; | ||
public static int[] in_org_1; | ||
public static boolean[] out; | ||
|
||
|
||
public static void load_test() { | ||
File fil = new File("judge/tests/subarray-sum.txt"); | ||
FileReader inputFil = null; | ||
try { | ||
inputFil = new FileReader(fil); | ||
} catch (FileNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
BufferedReader in = new BufferedReader(inputFil); | ||
try { | ||
in_0 = common.read_int_matrix(in); | ||
in_org_0 = test_common.copy(in_0); | ||
in_1 = common.read_int_array(in); | ||
in_org_1 = test_common.copy(in_1); | ||
out = common.read_bool_array(in); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static void judge() { | ||
load_test(); | ||
common.capture_stdout(); | ||
Solution s = new Solution(); | ||
|
||
long startTime = System.currentTimeMillis(); | ||
|
||
for(int i = 0; i < num_test; ++i) { | ||
System.out.printf("Testing case #%d\n", i+1); | ||
boolean answer = s.subarray_sum(in_0[i], in_1[i]); | ||
if(answer != out[i]) { | ||
common.release_stdout(); | ||
System.out.printf("%d / %d;", i+1, num_test); | ||
String outs = common.to_string(subarray_sum.in_org_0[i]) + ", " + common.to_string(subarray_sum.in_org_1[i]); | ||
System.out.print(outs + ";"); | ||
System.out.print(common.to_string(answer) + ";"); | ||
System.out.println(common.to_string(out[i])); | ||
return; | ||
} | ||
} | ||
|
||
common.release_stdout(); | ||
long estimatedTime = System.currentTimeMillis() - startTime; | ||
System.out.print("Accepted;"); | ||
System.out.println(estimatedTime); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require("../solution") | ||
|
||
local num_test = 100 | ||
local in_0 = {} | ||
local in_org_0 = {} | ||
local in_1 = {} | ||
local in_org_1 = {} | ||
local out = {} | ||
|
||
|
||
function load_test() | ||
local f = io.open("./judge/tests/subarray-sum.txt", "r") | ||
in_0 = read_num_matrix(f) | ||
in_org_0 = copy(in_0) | ||
in_1 = read_num_array(f) | ||
in_org_1 = copy(in_1) | ||
out = read_bool_array(f) | ||
f:close() | ||
end | ||
|
||
function judge() | ||
load_test() | ||
capture_stdout() | ||
|
||
local start = os.clock() | ||
for i = 1, num_test do | ||
print("Testing case #" .. i) | ||
local answer = subarray_sum(in_0[i], in_1[i]) | ||
if answer ~= out[i] then | ||
io.write(string.format("%d / %d;", i, num_test)) | ||
io.write(to_string(in_org_0[i])) | ||
io.write(", ") | ||
io.write(to_string(in_org_1[i])) | ||
io.write(";") | ||
io.write(to_string(answer)) | ||
io.write(";") | ||
io.write(to_string(out[i])) | ||
io.write("\n") | ||
return | ||
end | ||
end | ||
|
||
release_stdout() | ||
local elapsed = math.floor((os.clock() - start) * 1000) | ||
print("Accepted;" .. elapsed) | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from common import * | ||
from solution import * | ||
import copy | ||
import sys | ||
import datetime | ||
|
||
num_test = 100 | ||
true, false = True, False | ||
in_0 = [] | ||
in_org_0 = [] | ||
in_1 = [] | ||
in_org_1 = [] | ||
out = [] | ||
|
||
|
||
def load_test(): | ||
f = open('judge/tests/subarray-sum.txt', 'r') | ||
global in_0, in_org_0 | ||
in_0 = read_int_matrix(f) | ||
in_org_0 = copy.deepcopy(in_0) | ||
global in_1, in_org_1 | ||
in_1 = read_int_array(f) | ||
in_org_1 = copy.deepcopy(in_1) | ||
global out | ||
out = read_bool_array(f) | ||
f.close | ||
|
||
def judge(): | ||
load_test() | ||
capture_stdout() | ||
start_time = datetime.datetime.now() | ||
for i in range(num_test): | ||
print ('Testing case #' + str(i+1)) | ||
answer = subarray_sum(in_0[i], in_1[i]) | ||
if (answer != out[i]): | ||
release_stdout() | ||
out_str = str(i+1) + " / " + str(num_test) + ";" | ||
out_str += str(in_org_0[i]) | ||
out_str += ", " | ||
out_str += str(in_org_1[i]) | ||
out_str += ";" | ||
out_str += str(answer) | ||
out_str += ";" | ||
out_str += str(out[i]) | ||
print(out_str) | ||
return | ||
|
||
release_stdout() | ||
delta = datetime.datetime.now() - start_time | ||
runtime = str(int(delta.total_seconds() * 1000)) | ||
print('Accepted;' + runtime) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@num_test = 100 | ||
@in_0 = [] | ||
@in_org_0 = [] | ||
@in_1 = [] | ||
@in_org_1 = [] | ||
@out = [] | ||
|
||
|
||
def load_test | ||
f = File.new("judge/tests/subarray-sum.txt") | ||
@in_0 = read_int_matrix(f) | ||
@in_org_0 = @in_0.dup | ||
@in_1 = read_int_array(f) | ||
@in_org_1 = @in_1.dup | ||
@out = read_bool_array(f) | ||
f.close | ||
end | ||
|
||
def judge | ||
load_test | ||
capture_stdout | ||
|
||
start_time = Time.now | ||
|
||
(0...@num_test).each do |i| | ||
puts 'Testing case #' + (i+1).to_s | ||
answer = subarray_sum(@in_0[i], @in_1[i]) | ||
if answer != @out[i] | ||
release_stdout | ||
print "#{i+1} / #{@num_test};" | ||
print @in_org_0[i].to_s | ||
print ', ' | ||
print @in_org_1[i].to_s | ||
print ';' | ||
print answer.to_s | ||
print ';' | ||
print @out[i].to_s | ||
puts | ||
return | ||
end | ||
end | ||
|
||
release_stdout | ||
runtime = (Time.now - start_time) * 1000.0 | ||
puts('Accepted;' + runtime.to_i.to_s) | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package test | ||
import scala.io.Source | ||
import judge.common | ||
import judge.Solution | ||
|
||
object subarray_sum { | ||
val num_test = 100; | ||
var in_0 = List[List[Int]](); | ||
var in_1 = List[Int](); | ||
var out = List[](); | ||
|
||
|
||
def load_test() = { | ||
val in = Source.fromFile("./judge/tests/subarray-sum.txt").getLines; | ||
in_0 = common.read_int_matrix(in); | ||
in_1 = common.read_int_array(in); | ||
out = common.read_bool_array(in); | ||
} | ||
|
||
def judge(): Int = { | ||
load_test(); | ||
common.capture_stdout(); | ||
|
||
val startTime = System.currentTimeMillis(); | ||
var i = 0; | ||
|
||
while(i < num_test) { | ||
printf("Testing case #%d\n", i+1); | ||
val answer = Solution.subarray_sum(in_0(i), in_1(i)); | ||
if(answer != out(i)) { | ||
common.release_stdout(); | ||
printf("%d / %d;", i+1, num_test); | ||
var outs = common.to_string(subarray_sum.in_0(i)) + ", " + common.to_string(subarray_sum.in_1(i)); | ||
print(outs + ";"); | ||
print(common.to_string(answer) + ";"); | ||
println(common.to_string(out(i))); | ||
return 1; | ||
} | ||
i += 1; | ||
} | ||
|
||
common.release_stdout(); | ||
val estimatedTime = System.currentTimeMillis - startTime; | ||
print("Accepted;"); | ||
println(estimatedTime); | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.