Beginner Free Contest 37 - MINDIST

View as PDF

Submit solution

Points: 0.01 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem types
Allowed languages
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch

In case the statement didn't load correctly, you can download the statement here: Statement

Lưu ý: các bạn không nhập, xuất dữ liệu bằng file kể cả khi đề bài có yêu cầu. Đọc, ghi dữ liệu được thực hiện ở stdin và stdout.


Comments

Please read the guidelines before commenting.



  • -2
    YangKlee  commented on Jan. 12, 2025, 4:33 a.m. edit 2

    <#include <bits/stdc++.h>

    define ll long long

    define IOS iosbse::syncwith_stdio(false); cin.tie(NULL); cout.tie(NULL);

    define vti vector <int>

    define vtll vector <long long>

    define vtf vector <float>

    define str string

    define el cout << "\n"

    using namespace std; int main() { IOS; int n; cin >> n; vti a(n); int minDiff = 10e5, isFind = 0; for (int i = 0; i < n; i++) { cin >> a[i]; for (int j = 0; j < i; j++) { if (a[i] == a[j] && minDiff > abs(i - j)) { minDiff = abs(i - j); isFind = 1; } } } if (isFind) cout << minDiff << endl; else cout << -1 << endl;

    }/>


  • -7
    UruLuka  commented on Aug. 18, 2023, 9:48 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • 7
    ObitiDev  commented on June 27, 2022, 7:31 a.m.

    Bài MINDIST làm thế này 👇

    Sử dụng 1 mảng để lưu vị trí gần đây nhất mà giá trị x xuất hiện. Tới khi gặp một giá trị x mới thì kiểm tra, nếu thỏa mãn thì lưu vào một biến nhớ. (cái này bạn tự suy nghĩ kiếm cái tra cái gì)

    Kết quả sẽ là biến nhớ mà bạn lưu 😄

    Thế là xong bài


  • -57
    mhdttq  commented on Nov. 17, 2021, 1:10 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.