HANOI DEPARTMENT OF EDUCATION AND TRAINING
SCHOOL YEAR 2025 – 2026
Subject: INFORMATICS 11
Date: March 14, 2026 | Time: 120 Minutes
| No. | Problem Name | Program File | Input File | Output File | Points |
|---|---|---|---|---|---|
| 1 | Chess (Cờ vua) | COVUA.* | COVUA.INP | COVUA.OUT | 5.0 |
| 2 | Sorting (Sắp xếp) | SAPXEP.* | SAPXEP.INP | SAPXEP.OUT | 5.0 |
| 3 | Counting Pairs (Đếm cặp) | DEMCAP.* | DEMCAP.INP | DEMCAP.OUT | 4.0 |
| 4 | Spring Festival (Hội xuân) | HOIXUAN.* | HOIXUAN.INP | HOIXUAN.OUT | 4.0 |
| 5 | Shortest Segment (Đoạn con ngắn nhất) | DOANCON.* | DOANCON.INP | DOANCON.OUT | 2.0 |
An and Binh played $n$ consecutive chess games. There are no draws. Count who won more games.
Rearrange digits of a 4-digit number $N$ to form the largest number divisible by 5. Output -1 if impossible.
Find pairs $(x, y)$ where both are prime, $1 < x < y \le N$, and $y - x = K$.
Find triplets $(i, j, k)$ such that $\max(a_i, a_j, a_k) - \min(a_i, a_j, a_k) \le d$.
Find the shortest subsegment containing at least $k$ elements that have the maximum possible number of divisors in the array.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream fin("COVUA.INP");
ofstream fout("COVUA.OUT");
int n;
string s;
if (!(fin >> n >> s)) return 0;
int a = 0, b = 0;
for (char c : s) {
if (c == 'A') a++;
else if (c == 'B') b++;
}
if (a > b) fout << ">";
else if (a < b) fout << "<";
else fout << "=";
return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
int main() {
ifstream fin("SAPXEP.INP");
ofstream fout("SAPXEP.OUT");
string n;
fin >> n;
vector<int> digits;
bool hasFiveOrZero = false;
for (char c : n) {
int d = c - '0';
digits.push_back(d);
if (d == 0 || d == 5) hasFiveOrZero = true;
}
if (!hasFiveOrZero) {
fout << -1;
return 0;
}
sort(digits.rbegin(), digits.rend());
int lastDigitIdx = -1;
for (int i = digits.size() - 1; i >= 0; i--) {
if (digits[i] == 0 || digits[i] == 5) {
lastDigitIdx = i;
break;
}
}
int lastVal = digits[lastDigitIdx];
digits.erase(digits.begin() + lastDigitIdx);
for (int d : digits) fout << d;
fout << lastVal;
return 0;
}
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
const int MAXN = 1000005;
bool is_prime[MAXN];
void sieve() {
fill(is_prime + 2, is_prime + MAXN, true);
for (int p = 2; p * p < MAXN; p++) {
if (is_prime[p]) {
for (int i = p * p; i < MAXN; i += p)
is_prime[i] = false;
}
}
}
int main() {
ifstream fin("DEMCAP.INP");
ofstream fout("DEMCAP.OUT");
int n, k;
fin >> n >> k;
sieve();
int count = 0;
for (int x = 2; x <= n - k; x++) {
if (is_prime[x] && is_prime[x + k]) {
count++;
}
}
fout << count;
return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
int main() {
ifstream fin("HOIXUAN.INP");
ofstream fout("HOIXUAN.OUT");
int n;
long long d;
if (!(fin >> n >> d)) return 0;
vector<long long> a(n);
for (int i = 0; i < n; i++) fin >> a[i];
sort(a.begin(), a.end());
long long count = 0;
int left = 0;
for (int right = 0; right < n; right++) {
while (a[right] - a[left] > d) {
left++;
}
long long num_elements = right - left;
if (num_elements >= 2) {
count += (num_elements * (num_elements - 1)) / 2;
}
}
fout << count;
return 0;
}
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;
const int MAX_VAL = 10000001;
int divisor_count[MAX_VAL];
void precompute() {
for (int i = 1; i < MAX_VAL; i++) {
for (int j = i; j < MAX_VAL; j += i) {
divisor_count[j]++;
}
}
}
int main() {
ifstream fin("DOANCON.INP");
ofstream fout("DOANCON.OUT");
int n, k;
if (!(fin >> n >> k)) return 0;
precompute();
vector<int> a(n);
int max_divs = 0;
for (int i = 0; i < n; i++) {
fin >> a[i];
if (divisor_count[a[i]] > max_divs) max_divs = divisor_count[a[i]];
}
vector<int> indices;
for (int i = 0; i < n; i++) {
if (divisor_count[a[i]] == max_divs) indices.push_back(i);
}
if (indices.size() < k) fout << -1;
else {
int min_len = 2e9;
for (int i = 0; i <= (int)indices.size() - k; i++) {
min_len = min(min_len, indices[i + k - 1] - indices[i] + 1);
}
fout << min_len;
}
return 0;
}