Submission #1002763

# Submission time Handle Problem Language Result Execution time Memory
1002763 2024-06-19T19:26:44 Z Deepesson MalnaRISC (COI21_malnarisc) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
typedef std::pair<int,int> pii;
int main()
{
    int n;
    std::cin>>n;
    int oldn=n;
    int truenum=2;
    while(truenum<n){
        truenum*=2;
    }
    n=truenum;
    std::vector<std::vector<pii>> ans;
    for (int k = 2; k <= n; k *= 2){ // k is doubled every iteration
        for (int j = k/2; j > 0; j /= 2){ // j is halved at every iteration, with truncation of fractional parts
            std::vector<pii> tp;
            for (int i = 0; i < n; i++){
                int l = i ^ j;
                if (l > i)
                    if ( (i&k == 0)){
                        if(std::max(l+1,i+1)<=oldn)
                            tp.push_back({l+1,i+1});
                    }else {
                        if(std::max(l+1,i+1)<=oldn)
                            tp.push_back({i+1,l+1});
                    }
            }
            if(tp.size()){
                ans.push_back(tp);
            }
        }
    }
    std::cout<<ans.size()<<"\n";
    for(auto&x:ans){
        for(int v=0;v!=x.size();++v)std::cout<<"CMPSWP R"<<x[v].first<<" R"<<x[v].second<<((v==(x.size()-1))?"\n":" ");
    }
}

Compilation message

malnarisc.cpp: In function 'int main()':
malnarisc.cpp:20:31: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   20 |                     if ( (i&k == 0)){
      |                             ~~^~~~
malnarisc.cpp:19:20: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   19 |                 if (l > i)
      |                    ^
malnarisc.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int v=0;v!=x.size();++v)std::cout<<"CMPSWP R"<<x[v].first<<" R"<<x[v].second<<((v==(x.size()-1))?"\n":" ");
      |                     ~^~~~~~~~~~
malnarisc.cpp:35:94: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int v=0;v!=x.size();++v)std::cout<<"CMPSWP R"<<x[v].first<<" R"<<x[v].second<<((v==(x.size()-1))?"\n":" ");
      |                                                                                             ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB not sorted
2 Halted 0 ms 0 KB -