Submission #404785

# Submission time Handle Problem Language Result Execution time Memory
404785 2021-05-15T02:06:37 Z tqbfjotld MalnaRISC (COI21_malnarisc) C++14
100 / 100
2 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

vector<vector<pair<int,int> > > stuff(int n){
    if (n==2){
        vector<pair<int,int> > t;
        t.push_back({1,2});
        vector<vector<pair<int,int> > >ret;
        ret.push_back(t);
        return ret;
    }
    vector<vector<pair<int,int> > > ret;
    auto res = stuff(n/2);
    for (auto x : res){
        vector<pair<int,int> > t;
        for (auto y : x){
            t.push_back({y.first,y.second});
            t.push_back({n/2+y.first,n/2+y.second});
        }
        ret.push_back(t);
    }
    vector<pair<int,int> > t3;
    for (int x = 0; x<n/2; x++){
        t3.push_back({x+1,n-x});
    }
    ret.push_back(t3);
    int t2 = n/4;
    while (t2>0){
        vector<pair<int,int> > t;
        for (int x = 0; x<n; x++){
            if ((x&t2)==0){
                t.push_back({x+1,x+t2+1});
            }
        }
        ret.push_back(t);
        t2>>=1;
    }
    return ret;
}


int main(){
    int n;
    scanf("%d",&n);
    int t = 1;
    while (t<n) t<<=1;
    auto res = stuff(t);
    printf("%d\n",res.size());
    for (auto x : res){
        for (auto y : x){
            if (y.first>n || y.second>n) continue;
            printf("CMPSWP R%d R%d ",y.first,y.second);
        }
        printf("\n");
    }
}

Compilation message

malnarisc.cpp: In function 'int main()':
malnarisc.cpp:48:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wformat=]
   48 |     printf("%d\n",res.size());
      |             ~^    ~~~~~~~~~~
      |              |            |
      |              int          std::vector<std::vector<std::pair<int, int> > >::size_type {aka long unsigned int}
      |             %ld
malnarisc.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct