-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
5 changed files
with
145 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// http://codeforces.com/contest/1300/problem/A | ||
|
||
'use strict' | ||
|
||
const readInts = () => { | ||
return readline().split(' ').map(num => parseInt(num)) | ||
} | ||
|
||
const readInt = () => readInts()[0] | ||
|
||
let t = readInt() | ||
|
||
while (t --> 0) { | ||
const n = readInt() | ||
const arr = readInts() | ||
|
||
let ans = 0 | ||
let sum = 0 | ||
for (let i in arr) sum += arr[i] | ||
|
||
for (let i in arr) { | ||
if (!arr[i]) { | ||
arr[i] ++ | ||
ans ++ | ||
sum ++ | ||
} | ||
} | ||
|
||
if (!sum) { | ||
for (let i in arr) { | ||
if (arr[i] + 1 !== 0) { | ||
arr[i] ++ | ||
ans ++ | ||
break | ||
} | ||
} | ||
} | ||
|
||
print(ans) | ||
} |
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,22 @@ | ||
// http://codeforces.com/contest/1311/problem/A | ||
|
||
'use strict' | ||
|
||
let t = parseInt(readline()) | ||
|
||
while (t --> 0) { | ||
const arr = readline().split(' ').map(n => parseInt(n)) | ||
const a = arr[0] | ||
const b = arr[1] | ||
|
||
let ans = 0 | ||
const diff = Math.abs(a - b) | ||
if (a < b) { | ||
if (diff % 2) ans = 1 | ||
else ans = 2 | ||
} else if (a > b) { | ||
if (diff % 2) ans = 2 | ||
else ans = 1 | ||
} | ||
print(ans) | ||
} |
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,36 @@ | ||
// http://codeforces.com/contest/1311/problem/B | ||
|
||
'use strict' | ||
|
||
let t = parseInt(readline()) | ||
const readInts = () => readline().split(' ').map(n => parseInt(n)) | ||
const readInt = () => readInts[0] | ||
|
||
while (t --> 0) { | ||
const nm = readInts() | ||
const arr = readInts() | ||
const p = readInts() | ||
|
||
let found = true | ||
while (found) { | ||
found = false | ||
for (let i in p) { | ||
const pos = p[i] | ||
if (arr[pos - 1] > arr[pos]) { | ||
const tmp = arr[pos - 1] | ||
arr[pos - 1] = arr[pos] | ||
arr[pos] = tmp | ||
found = true | ||
} | ||
} | ||
} | ||
|
||
let ok = true | ||
for (let i = 1; i < arr.length; ++i) { | ||
if (arr[i - 1] > arr[i]) { | ||
ok = false | ||
break | ||
} | ||
} | ||
print(ok ? 'YES' : 'NO') | ||
} |
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,40 @@ | ||
// http://codeforces.com/contest/1311/problem/C | ||
|
||
'use strict' | ||
|
||
const getLine = () => readline().split(' ') | ||
const getInts = () => getLine().map(n => parseInt(n)) | ||
const getInt = () => getInts()[0] | ||
|
||
main() | ||
|
||
function main () { | ||
let t = getInt() | ||
while (t --> 0) { | ||
const params = getInts() | ||
const s = getLine()[0] | ||
const mistakes = getInts() | ||
solve(...params, s, mistakes) | ||
} | ||
} | ||
|
||
function solve (n, m, s, mistakes) { | ||
const freq = Array(n + 1).fill(0) | ||
const ans = Array(26).fill(0) | ||
let accumulate = 0 | ||
|
||
mistakes.push(n) | ||
|
||
for (const i of mistakes) { | ||
freq[0] ++ | ||
freq[i] -- | ||
} | ||
|
||
for (let i = 0; i < n; ++i) { | ||
const ind = s[i].charCodeAt() - 'a'.charCodeAt() | ||
accumulate += freq[i] | ||
ans[ind] += accumulate | ||
} | ||
|
||
print(ans.join(' ')) | ||
} |
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 |
---|---|---|
|
@@ -1067,4 +1067,10 @@ | |
32161457 | ||
31878123 | ||
31910741 | ||
32605600 | ||
32605600 | ||
71946383 | ||
71824279 | ||
71185827 | ||
71822449 | ||
71822118 | ||
71946544 |