Submission #1307566

#TimeUsernameProblemLanguageResultExecution timeMemory
1307566layedArranging Tickets (JOI17_arranging_tickets)C++20
10 / 100
206 ms580 KiB
#include <bits/stdc++.h>
#define int long long
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define pb push_back
#define pii pair<int,int>
#define str string
#define vec vector<int>
#define vecc vector<vector<int>>
#define f first
#define s second


using namespace std;
const int maxn = 1e6 + 1;
const int INF = 1e9 + 1;
const int mod = 1e9 + 7;


int binpow(int x, int n){
    int ans = 1;
    while(n){
        if(n % 2 == 1) ans = ans * x % mod;
        x = x * x % mod;
        n /= 2;  
    }
    return ans;
}

int a[maxn] , b[maxn] , n , m;
void solve(){
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
    	int c;
        cin >> a[i] >> b[i] >> c;
    }
    int ans = 1e18;
    for (int mask = 0; mask < (1 << m); mask++) {
        int used[21] = {0};
        for (int i = 1; i <= m; i++) {
            int cur = a[i];       
            int dir = (mask >> (i - 1)) & 1;
            if (dir == 0) {
                while (cur != b[i]) {
                    used[cur]++;
                    cur++;
                    if (cur > n) cur = 1;
                }
            } else {
                while (cur != b[i]) {
                    int p = cur - 1;
                    if (p == 0) p = n;
                    used[p]++;
                    cur = p;
                }
            }
        }
        int d = 0;
        for (int i = 1; i <= n; i++) {
            d = max(d, used[i]);
        }
        ans = min(ans, d);
    }
    cout << ans << '\n';
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0);
//	freopen("aplusb.in" , "r" , stdin);
//	freopen("aplusb.out" , "w" , stdout);
	int t = 1;
//	cin >> t;
	while(t--){
		solve();
	}
}
#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...