CSES - Practice Contest 2024 - Results
Submission details
Task:Interesting number
Sender:hefapa_aachen
Submission time:2024-09-28 12:26:23 +0300
Language:C++ (C++17)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails

Compiler report

input/code.cpp: In function 'bool palin(std::string)':
input/code.cpp:8:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define REP(i,a,b) for (int i = a; i < b; i++)
      |                                      ^
input/code.cpp:63:5: note: in expansion of macro 'REP'
   63 |     REP(i, 0, s.size()/2){
      |     ^~~

Code

// ~/.vim/cpp_template.cpp
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i,a,b) for (int i = a; i < b; i++)

// Type Aliases for 1D and 2D vectors with initialization
#define vi(n, val) vector<int>(n, val) // 1D vector of ints with size n, initialized to val
#define vll(n, val) vector<long long>(n, val) // 1D vector of long longs with size n, initialized to val
#define ll long long
#define vvi(n, m, val) vector<vector<int>>(n, vector<int>(m, val)) // 2D vector of ints (n x m), initialized to val
#define vvll(n, m, val) vector<vector<long long>>(n, vector<long long>(m, val)) // 2D vector of long longs (n x m), initialized to val


using namespace std;

template <typename T>
void pV(const std::vector<T>& vec, const std::string& label = "Vector") {
    std::cout << label << ": [ ";
    for (const auto& elem : vec) {
        std::cout << elem << " ";
    }
    std::cout << "]" << std::endl;
}


using namespace std;


void dfs(int s, vector<bool> *visited, vector<int> (*adj)[]) {
    if ((*visited)[s]) return;
    (*visited)[s] = true;
    // process node s


    for (auto u: (*adj)[s]) {
        dfs(u, visited, adj);
    }
}
/*
vector<int> adj[N];                                                          
vector<bool> visited(N, false);
int u, v;
for(int i = 0; i < M;i++){
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
}
*/
bool prime(long long n) {
    if (n < 2) return false;
    for (long long x = 2; x*x <= n; x++) {
        if (n%x == 0) return false;
    }
    return true;
}
bool palin(string s){
    REP(i, 0, s.size()/2){
        if(s[i] != s[s.size()-i-1]) return false;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // Your code starts here
    int t;
    cin >> t;
    REP(i, 0, t){
        int n;
        cin >> n;
        REP(i, 0, n){
            string s;
            cin >> s;
            if(palin(s)){
                if(prime(stoi(s))){
                    cout << s << endl;
                }
            }
        }
    }

    
    
    return 0;
}


Test details

Test 1

Verdict: ACCEPTED

input
1000
9
300 988 956 931 116 3 386 202 ...

correct output
3
3
181
919
191
...

user output
3
3
181
919
191
...
Truncated

Test 2

Verdict: ACCEPTED

input
1
100000
72 247 605 249 10 422 594 490 ...

correct output
191

user output
191