Submission #1344257

#TimeUsernameProblemLanguageResultExecution timeMemory
1344257SmuggingSpunA String Problem (EGOI25_stringproblem)C++20
100 / 100
38 ms10712 KiB
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
  int n;
  cin >> n;
  vector<int>a(n), b(n), cnt(n << 1, 0);
  for(int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
    cnt[(a[i] + b[i]) % (n << 1)]++;
  }
  int best_mod = 1;
  for(int mod = 3; mod < (n << 1); mod += 2){
    if(cnt[mod] > cnt[best_mod]){
      best_mod = mod;
    }
  }
  cout << n - cnt[best_mod] << "\n";
  vector<int>to(n << 1);
  for(int i = 0; i < n; i++){
    to[a[i]] = to[b[i]] = i;
  }
  function<void(int, int)>resolve;
  resolve = [&] (int id, int change){
    if((a[id] + b[id]) % (n << 1) != best_mod){
      if(a[id] != change){
        swap(a[id], b[id]);
      }
      cout << id << " " << change << " " << (a[id] = ((n << 1) + best_mod - b[id]) % (n << 1)) << "\n";
      resolve(to[a[id]], a[id]);
    }
  };
  for(int i = 0; i < n; i++){
    if((a[i] + b[i]) % (n << 1) != best_mod){
      resolve(i, a[i]);   
    }
  }
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:7:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...