답안 #456322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
456322 2021-08-06T12:10:35 Z urosk Xor Sort (eJOI20_xorsort) C++14
40 / 100
12 ms 1740 KB
///sat
#include <chrono>
using namespace std::chrono;
#define vremestart auto start = high_resolution_clock::now();
#define vremeend auto stop = high_resolution_clock::now();
#define vremeispis auto duration = duration_cast<microseconds>(stop - start); cout << duration.count() << endl;
///sat
#define here cerr<<"---------------------------\n"
#define popcount(x) __builtin_popcount(x) ///broj bitova
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define th third
#define fo fourth
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
using namespace std;
void setIO(string inoutname)
{
	freopen((inoutname+".in").c_str(),"r",stdin);
    	freopen((inoutname+".out").c_str(),"w",stdout);
}

ll gcd(ll a, ll b)
{
   if(b==0) return a;
   if(a==0) return b;
   if(a>=b)  return gcd(a%b,b);
   return  gcd(a,b%a);
}
#define maxn 1005
ll n,s;
ll a[maxn][30];
ll maxi[maxn];
vector<pll> ans;
void xor_(ll i,ll j){
    for(ll k = 0;k<25;k++){
        a[i][k]^=a[j][k];
    }
    for(ll k = 25;k>=0;k--){
        if(a[i][k]!=0){
            maxi[i] = k;
            break;
        }
    }
    ans.pb({i,j});
    //cerr<<i<< " "<<j<<endl;
    return;
}
ll dec(ll i){
    ll ans = 0;
    ll dv = 1;
    for(ll j = 0;j<=19;j++){
        if(a[i][j]==1) ans+=dv;
        dv*=2;
    }
    return ans;
}
void tc(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    cin >> n >> s;
    ll x;
    for(ll i = 1;i<=n;i++){
        cin >> x;
        ll j = 0;
        while(x>0){
            ll f = x%2;
            a[i][j] = f;
            x/=2;
            if(f==1) maxi[i] = j;
            j++;
        }
    }
    /*for(ll i = 1;i<=n;i++){
        for(ll j = 19;j>=0;j--) cout<<a[i][j];
        cout<<endl;
    }*/
    //here;
    ll m = n;
    for(ll k = 25;k>=0;k--){
        for(ll i = 1;i<m;i++){
            if(a[i][k]==0) continue;
            for(ll j = i;j<m;j++){
                if(a[j+1][k]==0){
                    xor_(j+1,j);
                }
            }
            for(ll j = i;j<m;j++){
                xor_(j,j+1);
            }
            m--;
            break;
        }
        //for(ll i = 1;i<=n;i++) cerr<<dec(i)<< " ";
        //cerr<<endl;
    }
    //here;
    cout<<sz(ans)<<endl;
    for(pll p : ans){
        cout<<p.fi<< " "<<p.sc<<endl;
    }
    /*for(ll i = 1;i<=n;i++){
        for(ll j = 25;j>=0;j--) cout<<a[i][j];
        cout<<endl;
    }*/
}
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	//setIO("lol");
	int t; t = 1;
	while(t--){
		tc();
	}
	return 0;
}

Compilation message

xorsort.cpp: In function 'void setIO(std::string)':
xorsort.cpp:32:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xorsort.cpp:33:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |      freopen((inoutname+".out").c_str(),"w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Incorrect 1 ms 332 KB Not sorted
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Incorrect 1 ms 332 KB Not sorted
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 8 ms 1356 KB Output is correct
6 Correct 10 ms 1344 KB Output is correct
7 Correct 8 ms 1392 KB Output is correct
8 Correct 10 ms 1356 KB Output is correct
9 Correct 8 ms 1356 KB Output is correct
10 Correct 8 ms 1356 KB Output is correct
11 Correct 8 ms 1356 KB Output is correct
12 Correct 8 ms 1348 KB Output is correct
13 Correct 8 ms 1356 KB Output is correct
14 Correct 8 ms 1372 KB Output is correct
15 Correct 12 ms 1740 KB Output is correct